com.guiseframework.model
Class FileItemResourceImport

java.lang.Object
  extended by com.guiseframework.model.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
FileItemResourceImport(FileItem fileItem)
          File item constructor.
 
Method Summary
 long getContentLength()
           
 com.globalmentor.net.ContentType getContentType()
           
protected  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(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 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:
getSimpleName()

getSimpleName

public java.lang.String getSimpleName()
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:
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
Retrieves an input stream to the resource. There can only be at most a single call to this method or store(File).

Specified by:
getInputStream in interface ResourceImport
Returns:
An input stream to the resource to be imported.
Throws:
java.lang.IllegalStateException - if this resource has already been stored in a file, or an input stream to the resource has already been retrieved.
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
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 getInputStream().

Specified by:
store in interface ResourceImport
Parameters:
file - The file to which the resource should be written.
Throws:
java.lang.IllegalStateException - if this resource has already been stored in a file, or an input stream to the resource has already been retrieved.
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
Returns:
A string representation of this resource import.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.