Class FileItemResourceImport

java.lang.Object
io.guise.framework.model.FileItemResourceImport
All Implemented Interfaces:
ResourceImport

public class FileItemResourceImport extends 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 Details

    • FileItemResourceImport

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

    • 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 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:
    • getSimpleName

      public 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:
    • getContentType

      public com.globalmentor.net.MediaType 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 InputStream getInputStream() throws 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:
      IOException - if there is an error getting an input stream to the resource.
    • store

      public void store(File file) throws 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:
      IOException - If there is an error writing the resource to the file.
    • toString

      public String toString()
      Overrides:
      toString in class Object