Class LocalFile

java.lang.Object
org.apache.juneau.cp.LocalFile

public class LocalFile extends Object
Identifies a file located either on the classpath or file system. Used to encapsulate basic resolution and retrieval of files regardless of where they are located.
See Also:
  • Constructor Details

    • LocalFile

      public LocalFile(Class<?> clazz, String clazzPath)
      Constructor for classpath file.
      Parameters:
      clazz - The class used to retrieve resources. Must not be null.
      clazzPath - The path relative to the class. Must be a non-null normalized relative path.
    • LocalFile

      public LocalFile(Path path)
      Constructor for file system file.
      Parameters:
      path - Filesystem file location. Must not be null.
  • Method Details

    • read

      public InputStream read() throws IOException
      Returns the contents of this file.
      Returns:
      An input stream of the contents of this file.
      Throws:
      IOException - If file could not be read.
    • size

      public long size() throws IOException
      Returns the size of this file.
      Returns:
      The size of this file in bytes, or -1 if not known.
      Throws:
      IOException - If file size could not be determined.
    • cache

      public LocalFile cache() throws IOException
      Caches the contents of this file into an internal byte array for quick future retrieval.
      Returns:
      This object.
      Throws:
      IOException - If file could not be read.
    • getName

      public String getName()
      Returns the name of this file.
      Returns:
      The name of this file.