Package gov.usgs.earthquake.product
Class FileContent
java.lang.Object
gov.usgs.earthquake.product.AbstractContent
gov.usgs.earthquake.product.FileContent
- All Implemented Interfaces:
Content
Content stored in a file.
-
Constructor Summary
ConstructorsConstructorDescriptionFileContent
(Content content, File toWrite) Convert a Content to a file backed content.FileContent
(URLContent urlc) Construct a new FileContent from a URLContent for legacy productsFileContent
(File file) Construct a new FileContent that does not use a nested path. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Free any resources associated with this content.protected static String
defaultGetMimeType
(File file) Check a local list of mime types, and fall back to MimetypeFileTypesMap if not specified.static Map<String,
FileContent> getDirectoryContents
(File directory) Search a directory for files.static Map<String,
FileContent> getDirectoryContents
(File directory, File baseDirectory) Search a directory for files.getFile()
The content bytes as a stream.getMimeType
(File file) This implementation calls defaultGetMimeType, and exists so subclasses can override.Methods inherited from class gov.usgs.earthquake.product.AbstractContent
getContentType, getLastModified, getLength, getSha256, getSha256, setContentType, setLastModified, setLength, setSha256
-
Constructor Details
-
FileContent
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
Construct a new FileContent from a URLContent for legacy products- Parameters:
urlc
- the source of content.- Throws:
URISyntaxException
- if error in URI
-
FileContent
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
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
- Returns:
- the wrapped file.
-
getDirectoryContents
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
This implementation calls defaultGetMimeType, and exists so subclasses can override.- Parameters:
file
- file to check.- Returns:
- corresponding mime type.
-
defaultGetMimeType
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.
-