Class FileItemResourceImport

  • All Implemented Interfaces:
    ResourceImport

    public class FileItemResourceImport
    extends java.lang.Object
    implements ResourceImport
    A resource import that accesses a web file upload through the Apache commons file item interface.
    Author:
    Garret Wilson
    See Also:
    FileItem
    • Constructor Summary

      Constructors 
      Constructor Description
      FileItemResourceImport​(org.apache.commons.fileupload.FileItem fileItem)
      File item constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getContentLength()  
      com.globalmentor.net.ContentType getContentType()  
      protected org.apache.commons.fileupload.FileItem getFileItem()  
      java.io.InputStream getInputStream()
      Retrieves an input stream to the resource.
      java.lang.String getName()  
      java.lang.String getSimpleName()
      Returns the simple name, such as the filename, of the resource.
      boolean isImported()  
      void store​(java.io.File file)
      Convenience method for storing the imported resource in a file.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • FileItemResourceImport

        public FileItemResourceImport​(org.apache.commons.fileupload.FileItem fileItem)
        File item constructor.
        Parameters:
        fileItem - The Apache commons file item representing a file upload.
        Throws:
        java.lang.NullPointerException - if the given file item is null.
    • Method Detail

      • getFileItem

        protected org.apache.commons.fileupload.FileItem getFileItem()
        Returns:
        The Apache commons file item representing a file upload.
      • isImported

        public boolean isImported()
        Specified by:
        isImported in interface ResourceImport
        Returns:
        Whether the resource has been accessed, either by retrieving its input stream or by storing the resource in a file.
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface ResourceImport
        Returns:
        The name of the resource, which may be, for example, a simple name, a path and filename, or null if the name is not known.
        See Also:
        ResourceImport.getSimpleName()
      • getSimpleName

        public java.lang.String getSimpleName()
        Description copied from interface: ResourceImport
        Returns the simple name, such as the filename, of the resource. The returned string does not include any path information.
        Specified by:
        getSimpleName in interface ResourceImport
        Returns:
        The simple name of the resource, or null if the name is not known.
        See Also:
        ResourceImport.getName()
      • getContentType

        public com.globalmentor.net.ContentType getContentType()
        Specified by:
        getContentType in interface ResourceImport
        Returns:
        The content type of the resource to be imported, or null if the content type of the resource is not known.
      • getContentLength

        public long getContentLength()
        Specified by:
        getContentLength in interface ResourceImport
        Returns:
        The length of the resource to be imported, or -1 if the length of the resource is not known.
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Description copied from interface: ResourceImport
        Retrieves an input stream to the resource. There can only be at most a single call to this method or ResourceImport.store(File).
        Specified by:
        getInputStream in interface ResourceImport
        Returns:
        An input stream to the resource to be imported.
        Throws:
        java.io.IOException - if there is an error getting an input stream to the resource.
      • store

        public void store​(java.io.File file)
                   throws java.io.IOException
        Description copied from interface: ResourceImport
        Convenience method for storing the imported resource in a file. Depending on the implementation, this may allow greater efficiency than reading from the stream. There can only be at most a single call to this method or ResourceImport.getInputStream().
        Specified by:
        store in interface ResourceImport
        Parameters:
        file - The file to which the resource should be written.
        Throws:
        java.io.IOException - If there is an error writing the resource to the file.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object