public class URLFileItem extends Object implements org.apache.commons.fileupload.FileItem
IAttachmentsProvider provider; //get or create attachment provider here //add a local text file FileItem item = new URLFileItem(new File("c:\\file.txt")); provider.addAttachment(item, "UTF-8"); //add a local binary file FileItem item2 = new URLFileItem(new File("c:\\file.gif")); provider.addAttachment(item, null); //add a remote binary file FileItem item2 = new URLFileItem(new URL("http://localhost/file.gif")); provider.addAttachment(item, null); //add a web application resource file FileItem item2 = new URLFileItem("/MyPortlet/myfile.gif"); provider.addAttachment(item, null);When used in a java bean context
location
property should be set with a URL, local
file path or a web resource path.Modifier and Type | Field and Description |
---|---|
protected URLConnection |
connection
Holds the connection to the file URL
|
protected URL |
fileUrl
Holds the file URL
|
protected String |
location
Holds the location of the file
|
Constructor and Description |
---|
URLFileItem()
Default Constructor.
|
URLFileItem(File localFile)
FileItem for a local file.
|
URLFileItem(String location)
FileItem for a location
|
URLFileItem(URL fileUrl)
FileItem for any URL
|
Modifier and Type | Method and Description |
---|---|
void |
delete()
Not Implemented.
|
byte[] |
get()
Not Implemented.
|
protected URLConnection |
getConnection()
Returns a connection to the file URL
|
String |
getContentType()
Returns the ContentType returned by the URL connection.
|
String |
getFieldName()
Not Implemented.
|
org.apache.commons.fileupload.FileItemHeaders |
getHeaders()
Not Implemented.
|
InputStream |
getInputStream()
Returns the InputStream returned by the URL connection.
|
String |
getLocation()
Gets the location of the file
|
String |
getName()
Returns the last segment of the URL.
|
OutputStream |
getOutputStream()
Not Implemented.
|
long |
getSize()
Returns the ContentLength returned by the URL connection.
|
String |
getString()
Not Implemented.
|
String |
getString(String arg0)
Not Implemented.
|
boolean |
isFormField()
Not Implemented.
|
boolean |
isInMemory()
Not Implemented.
|
void |
setFieldName(String arg0)
Not Implemented.
|
void |
setFormField(boolean arg0)
Not Implemented.
|
void |
setHeaders(org.apache.commons.fileupload.FileItemHeaders headers)
Not Implemented.
|
void |
setLocation(String location)
Initializes bean with file location which can be either URL, local file fully qualified path,
or web application resource path
|
void |
write(File arg0)
Not Implemented.
|
protected URL fileUrl
protected URLConnection connection
protected String location
public URLFileItem()
public URLFileItem(File localFile) throws MalformedURLException
localFile
- the local file to useMalformedURLException
public URLFileItem(URL fileUrl)
fileUrl
- the URL of the filepublic URLFileItem(String location)
location
- the location of the filepublic String getLocation()
public void setLocation(String location)
location
- file locationprotected URLConnection getConnection()
public String getName()
getName
in interface org.apache.commons.fileupload.FileItem
FileItem.getName()
public String getContentType()
getContentType
in interface org.apache.commons.fileupload.FileItem
FileItem.getContentType()
,
URLConnection.getContentType()
public long getSize()
getSize
in interface org.apache.commons.fileupload.FileItem
FileItem.getSize()
,
URLConnection.getContentLength()
public InputStream getInputStream() throws IOException
getInputStream
in interface org.apache.commons.fileupload.FileItem
IOException
FileItem.getInputStream()
public void delete()
delete
in interface org.apache.commons.fileupload.FileItem
public byte[] get()
get
in interface org.apache.commons.fileupload.FileItem
public String getFieldName()
getFieldName
in interface org.apache.commons.fileupload.FileItem
public OutputStream getOutputStream() throws IOException
getOutputStream
in interface org.apache.commons.fileupload.FileItem
IOException
public String getString()
getString
in interface org.apache.commons.fileupload.FileItem
public String getString(String arg0) throws UnsupportedEncodingException
getString
in interface org.apache.commons.fileupload.FileItem
UnsupportedEncodingException
public boolean isFormField()
isFormField
in interface org.apache.commons.fileupload.FileItem
public boolean isInMemory()
isInMemory
in interface org.apache.commons.fileupload.FileItem
public void setFieldName(String arg0)
setFieldName
in interface org.apache.commons.fileupload.FileItem
public void setFormField(boolean arg0)
setFormField
in interface org.apache.commons.fileupload.FileItem
public void write(File arg0) throws Exception
write
in interface org.apache.commons.fileupload.FileItem
Exception
public org.apache.commons.fileupload.FileItemHeaders getHeaders()
getHeaders
in interface org.apache.commons.fileupload.FileItemHeadersSupport
public void setHeaders(org.apache.commons.fileupload.FileItemHeaders headers)
setHeaders
in interface org.apache.commons.fileupload.FileItemHeadersSupport