Class FileContent

  • All Implemented Interfaces:
    Content

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

      • FileContent

        public FileContent​(java.io.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 java.net.URISyntaxException
        Construct a new FileContent from a URLContent for legacy products
        Parameters:
        urlc - the source of content.
        Throws:
        java.net.URISyntaxException - if error in URI
      • FileContent

        public FileContent​(Content content,
                           java.io.File toWrite)
                    throws java.io.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:
        java.io.IOException - if IO error occurs
    • Method Detail

      • getInputStream

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

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

        public static java.util.Map<java.lang.String,​FileContent> getDirectoryContents​(java.io.File directory)
                                                                                      throws java.io.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:
        java.io.IOException - if IO error occurs
      • getDirectoryContents

        public static java.util.Map<java.lang.String,​FileContent> getDirectoryContents​(java.io.File directory,
                                                                                             java.io.File baseDirectory)
                                                                                      throws java.io.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:
        java.io.IOException - if IO error occurs
      • getMimeType

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

        protected static java.lang.String defaultGetMimeType​(java.io.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.