|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.clients.web.fileupload.FileUpload
public class FileUpload
Objects of this class are used to handle file upload from browsers using the standard mechanism described in RFC1867.
Nested Class Summary | |
---|---|
private static class |
FileUpload.SectionHeaders
This class contains information extracted from the section headers for a form field or file upload field. |
private static class |
FileUpload.UploadStatus
This class contains information about the read status on the ServletInputStream |
private class |
FileUpload.UploadStream
|
Field Summary | |
---|---|
private byte[] |
boundary
The multipart/formdata boundary |
static long |
DEFAULT_TIMEOUT
The default timeout to use when waiting for the next data packet to arrive. |
private static String |
EMPTY_STRING
|
private static Pattern |
FILENAME_PATTERN
|
private Map<String,List<UploadedFile>> |
files
Contains information about uploaded files name --> UploadedFile |
private ServletInputStream |
in
The stream coming from the browser. |
private static Logger |
log
Debug file upload. |
private static Pattern |
NAME_PATTERN
|
private Map<String,List<String>> |
parameters
Contains information about regular input field parameters name --> value |
private FileUploadProgress |
progress
Progress information for the upload |
private FileUpload.UploadStatus |
status
The status of the upload. |
private long |
timeout
The timeout in milliseconds that we wait for more data to arrive. |
private int |
transferRate
The maximum transefer rate (bytes/second) |
Constructor Summary | |
---|---|
FileUpload(ServletRequest request)
Create a new FileUpload object which will read the posted
data from the given ServletRequest object. |
|
FileUpload(ServletRequest request,
int transferRate,
long timeout)
Create a new FileUpload object which will read the posted
data from the given ServletRequest object limiting the
transfer rate. |
Method Summary | |
---|---|
private void |
addFile(String name,
UploadedFile file)
Store information about an uploaded file. |
private void |
addParameter(String name,
String value)
Store the value of a regular form field. |
private void |
checkAbortAndDelay()
Check if upload has been aborted. |
private void |
checkBoundary(byte[] line,
int lineLength,
byte[] boundary,
int boundaryLength)
Check if the given line matches the boundary . |
(package private) void |
doUpload(OutputStream out,
UploadedFile uf)
Upload a single file section to the specified output stream |
boolean |
eof()
Check if the end of the upload has been reached or not. |
UploadedFile |
getFile(String name)
Get the file information for an uplodaded file. |
UploadedFile[] |
getFileValues(String name)
Get the file information for uplodaded files. |
private String |
getHeaderAttribute(String header,
Pattern p)
|
(package private) InputStream |
getInputStream(UploadedFile uf)
Get an input stream for reading from the current file section. |
String |
getParameter(String name)
Get the value for a form field. |
Iterator |
getParameterNames()
Get the names for all fields used in the form, excluding file input fields. |
String[] |
getParameterValues(String name)
Get an array of values for a form field. |
FileUploadProgress |
getProgress()
Get progress information about the upload. |
UploadedFile |
next()
Read from the input stream until a file section is found or the end is encountered. |
private String |
readFormData(byte[] boundary)
Read from ServletInputStream until the boundary is found. |
private int |
readLine(byte[] b,
int off,
int len)
Read next line of data into a buffer. |
private String |
readLineAsString()
Reads the next line of input and returns it as a string. |
private FileUpload.SectionHeaders |
readSectionHeaders()
Read from ServletInputStream until an empty line is found. |
private void |
readToBoundary(byte[] boundary)
Read from ServletInputStream until the boundary is found on a line by itself. |
void |
setException(Throwable t)
Set exception information on the associated FileUploadProgress
object. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Logger log
public static final long DEFAULT_TIMEOUT
private static final String EMPTY_STRING
private Map<String,List<String>> parameters
private Map<String,List<UploadedFile>> files
private ServletInputStream in
private FileUpload.UploadStatus status
private FileUploadProgress progress
private byte[] boundary
private int transferRate
private long timeout
private static final Pattern NAME_PATTERN
private static final Pattern FILENAME_PATTERN
Constructor Detail |
---|
public FileUpload(ServletRequest request) throws IOException, UploadAbortedException
FileUpload
object which will read the posted
data from the given ServletRequest
object.
request
- The ServletRequest
object containg information
about the request (and file upload)
IOException
- If there is an error reading from the request stream
UploadAbortedException
- If the upload was abortedpublic FileUpload(ServletRequest request, int transferRate, long timeout) throws IOException, UploadAbortedException
FileUpload
object which will read the posted
data from the given ServletRequest
object limiting the
transfer rate.
request
- The ServletRequest
object containg information
about the request (and file upload)transferRate
- The maximum transfer rate in bytes per second, or 0
to transfer as fast as possibletimeout
- The timeout in milliseconds to wait for the next packet
of data to arrive
IOException
- If there is an error reading from the request stream
UploadAbortedException
- If the upload was abortedMethod Detail |
---|
public FileUploadProgress getProgress()
public boolean eof()
public UploadedFile next() throws IOException, UploadAbortedException
UploadedFile
object with information about the next file
section, or null if there are no more file sections
IOException
- If reading the file fails.
UploadAbortedException
- If the uploaded has been requested to abort.void doUpload(OutputStream out, UploadedFile uf) throws IOException, UploadAbortedException
IOException
UploadAbortedException
InputStream getInputStream(UploadedFile uf) throws IOException
IOException
private void addParameter(String name, String value)
name
- The name of the form fieldvalue
- The valueprivate void addFile(String name, UploadedFile file)
name
- The name of the form fieldfile
- A UploadedFile
object containing information
about the uploaded filepublic String getParameter(String name)
getParameterValues(String)
method.
name
- The name of the form field
getParameterValues(String)
public String[] getParameterValues(String name)
getParameter(String)
method.
name
- The name of the form field
getParameter(String)
public Iterator getParameterNames()
Iterator
object that can be used to iterate through
the collection of form fieldspublic UploadedFile getFile(String name)
getFileValues(String)
method.
name
- The name of the upload form field
UploadedFile
object or NULL if it the field with this name is not foundgetFileValues(String)
public UploadedFile[] getFileValues(String name)
getFile(String)
method.
name
- The name of the upload form field(s)
UploadedFile
objects or NULL if it no fields with
this name are not foundgetFile
public void setException(Throwable t)
FileUploadProgress
object. This is a useful way to communicate if the uploading is done
by one thread and the progress display in another. This method is also called
if an exception occures internally in this object.
t
- The throwable object to set.private String getHeaderAttribute(String header, Pattern p)
private void checkBoundary(byte[] line, int lineLength, byte[] boundary, int boundaryLength)
line
matches the boundary
.
The line
always has an extra CRLF pair at the end and may also have
two dashes (--). The two dashes indicates the end of the input for the form.
private String readLineAsString() throws IOException
IOException
private String readFormData(byte[] boundary) throws IOException, UploadAbortedException
IOException
UploadAbortedException
private void readToBoundary(byte[] boundary) throws IOException, UploadAbortedException
IOException
UploadAbortedException
private FileUpload.SectionHeaders readSectionHeaders() throws IOException, UploadAbortedException
SectionHeaders
object with information about the headers found
IOException
UploadAbortedException
private void checkAbortAndDelay() throws UploadAbortedException
UploadAbortedException
private int readLine(byte[] b, int off, int len) throws IOException
IOException
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |