2.17.2: 2011-06-17

net.sf.basedb.clients.web.fileupload
Class UploadedFile

java.lang.Object
  extended by net.sf.basedb.clients.web.fileupload.UploadedFile

public class UploadedFile
extends Object

Objects of this class can be used to get information about an uploaded file and save the file to a directory in the filesystem. If the file is not saved, it will be deleted once the object is garbage collected.

Version:
2.0
Author:
Nicklas

Field Summary
private  String filename
           
private  String formName
           
private  FileUpload fu
           
private  String mimeType
           
 
Constructor Summary
UploadedFile(FileUpload fu, String formName, String filename, String mimeType)
          Create a new UploadedFile object.
 
Method Summary
 String getExtension()
          Get the extension of the original filename.
 String getFilename()
          Get the original filename of the uploaded file.
 String getFormName()
          Get the name of the form field that this file was selected in.
 InputStream getInputStream()
          Get an input stream for uploading the file.
 String getMimeType()
          Get the MIME type of the uploaded file.
 void writeTo(OutputStream out)
          Upload the file and write the data to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

fu

private FileUpload fu

formName

private final String formName

filename

private final String filename

mimeType

private final String mimeType
Constructor Detail

UploadedFile

UploadedFile(FileUpload fu,
             String formName,
             String filename,
             String mimeType)
Create a new UploadedFile object. Use the FileUpload.getFile(String) or FileUpload.getFileValues(String) method to get an object representing the uploaded file.

Parameters:
fu - The FileUpload object responsible for the upload
formName - The name of the form field with this file
mimeType - The MIME type of the file, or NULL if it is not known
filename - The original filename of the file, or NULL if it is not known
Method Detail

getFormName

public String getFormName()
Get the name of the form field that this file was selected in.

Since:
2.16

getFilename

public String getFilename()
Get the original filename of the uploaded file. This is the name the file had on the client computer.

Returns:
The original name of the file, or NULL if it is not known

getExtension

public String getExtension()
Get the extension of the original filename. The extension is the part of the filename after the last dot. If the file doesn't have an extension NULL is returned.

Returns:
The extension of the file, or NULL if none exists

getMimeType

public String getMimeType()
Get the MIME type of the uploaded file.

Returns:
The MIME type of the file, or NULL if it is not known

writeTo

public void writeTo(OutputStream out)
             throws IOException,
                    UploadAbortedException
Upload the file and write the data to the specified output stream.

Parameters:
out - The stream to write to
Throws:
IOException
UploadAbortedException

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  UploadAbortedException
Get an input stream for uploading the file.

Returns:
An input stream to read from
Throws:
IOException - If reading the input stream fails.
UploadAbortedException - If the upload has been requested to be aborted.

2.17.2: 2011-06-17