Class FileContent

java.lang.Object
gov.usgs.earthquake.product.AbstractContent
gov.usgs.earthquake.product.FileContent
All Implemented Interfaces:
Content

public class FileContent extends AbstractContent
Content stored in a file.
  • Constructor Details

    • FileContent

      public FileContent(File file)
      Construct a new FileContent that does not use a nested path. same as new FileContent(file, file.getParentFile());
      Parameters:
      file - the source of content.
    • FileContent

      public FileContent(URLContent urlc) throws URISyntaxException
      Construct a new FileContent from a URLContent for legacy products
      Parameters:
      urlc - the source of content.
      Throws:
      URISyntaxException - if error in URI
    • FileContent

      public FileContent(Content content, File toWrite) throws IOException
      Convert a Content to a file backed content. The file written is new File(baseDirectory, content.getPath()).
      Parameters:
      content - the content that will be converted to a file.
      toWrite - the file where content is written.
      Throws:
      IOException - if IO error occurs
  • Method Details

    • getInputStream

      public InputStream getInputStream() throws IOException
      Description copied from interface: Content
      The content bytes as a stream.
      Returns:
      an InputStream for the wrapped content.
      Throws:
      IOException - if an error occurs while creating the stream.
    • getFile

      public File getFile()
      Returns:
      the wrapped file.
    • getDirectoryContents

      public static Map<String,FileContent> getDirectoryContents(File directory) throws IOException
      Search a directory for files. This is equivalent to getDirectoryContents(directory, directory).
      Parameters:
      directory - the directory to search.
      Returns:
      a map of relative paths to FileContent objects.
      Throws:
      IOException - if IO error occurs
    • getDirectoryContents

      public static Map<String,FileContent> getDirectoryContents(File directory, File baseDirectory) throws IOException
      Search a directory for files. The path to files relative to baseDirectory is used as a key in the returned map.
      Parameters:
      directory - the directory to search.
      baseDirectory - the directory used to compute relative paths.
      Returns:
      a map of relative paths to FileContent objects.
      Throws:
      IOException - if IO error occurs
    • getMimeType

      public String getMimeType(File file)
      This implementation calls defaultGetMimeType, and exists so subclasses can override.
      Parameters:
      file - file to check.
      Returns:
      corresponding mime type.
    • defaultGetMimeType

      protected static String defaultGetMimeType(File file)
      Check a local list of mime types, and fall back to MimetypeFileTypesMap if not specified.
      Parameters:
      file - file to check.
      Returns:
      corresponding mime type.
    • close

      public void close()
      Free any resources associated with this content.