java.lang.Objectorg.apache.tomcat.util.http.fileupload.MultipartStream
Low level API for processing file uploads.
This class can be used to process data streams conforming to MIME 'multipart' format as defined in RFC 1867. Arbitrarily large amounts of data in the stream can be processed under constant memory usage.
The format of the stream is defined in the following way:
multipart-body := preamble 1*encapsulation close-delimiter epilogue
encapsulation := delimiter body CRLF
delimiter := "--" boundary CRLF
close-delimiter := "--" boudary "--"
preamble := <ignore>
epilogue := <ignore>
body := header-part CRLF body-part
header-part := 1*header CRLF
header := header-name ":" header-value
header-name := <printable ascii characters except ":">
header-value := <any ascii characters except CR & LF>
body-data := <arbitrary data>
Note that body-data can contain another mulipart entity. There is limited support for single pass processing of such nested streams. The nested stream is required to have a boundary token of the same length as the parent stream (see #setBoundary(byte[]) ).
Here is an exaple of usage of this class.
try { MultipartStream multipartStream = new MultipartStream(input, boundary); boolean nextPart = malitPartStream.skipPreamble(); OutputStream output; while(nextPart) { header = chunks.readHeader(); // process headers // create some output stream multipartStream.readBodyPart(output); nextPart = multipartStream.readBoundary(); } } catch(MultipartStream.MalformedStreamException e) { // the stream failed to follow required syntax } catch(IOException) { // a read or write error occurred }
- href="mailto:Rafal.Krzewski@e-point.pl">Rafal Krzewski
- href="mailto:martinc@apache.org">Martin Cooper
Sean
- C. Sullivan$
- Id: MultipartStream.java 467222 2006-10-24 03:17:11Z markt $Nested Class Summary: | ||
---|---|---|
public class | MultipartStream.MalformedStreamException | Thrown to indicate that the input stream fails to follow the required syntax. |
public class | MultipartStream.IllegalBoundaryException | Thrown upon attempt of setting an invalid boundary token. |
Field Summary | ||
---|---|---|
public static final int | HEADER_PART_SIZE_MAX | The maximum length of header-part that will be
processed (10 kilobytes = 10240 bytes.). |
protected static final int | DEFAULT_BUFSIZE | The default length of the buffer used for processing a request. |
protected static final byte[] | HEADER_SEPARATOR | A byte sequence that marks the end of header-part
(CRLFCRLF ). |
protected static final byte[] | FIELD_SEPARATOR | A byte sequence that that follows a delimiter that will be
followed by an encapsulation (CRLF ). |
protected static final byte[] | STREAM_TERMINATOR | A byte sequence that that follows a delimiter of the last
encapsulation in the stream (-- ). |
Constructor: |
---|
|
Constructs a
|
Constructs a Note that the buffer must be at least big enough to contain the boundary string, plus 4 characters for CR/LF and double dash, plus at least one byte of data. Too small a buffer size setting will degrade performance.
|
Method from org.apache.tomcat.util.http.fileupload.MultipartStream Summary: |
---|
arrayequals, discardBodyData, findByte, findSeparator, getHeaderEncoding, readBodyData, readBoundary, readByte, readHeaders, setBoundary, setHeaderEncoding, skipPreamble, toString |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from org.apache.tomcat.util.http.fileupload.MultipartStream Detail: |
---|
count first bytes in the arrays
a and b . |
Reads Use this method to skip encapsulations you don't need or don't understand. |
buffer ,
starting at the specified position . |
boundary in the buffer
region delimited by head and tail . |
null , the platform
default encoding is used. |
Reads Arbitrary large amounts of data can be processed by this method using a constant size buffer. (see constructor ). |
boundary token, and checks whether more
encapsulations are contained in the stream. |
buffer , and refills it as
necessary. |
Reads the Headers are returned verbatim to the input stream, including the
trailing TODO allow limiting maximum header size to protect against abuse. |
Changes the boundary token used for partitioning the stream. This method allows single pass processing of nested multipart streams. The boundary token of the nested stream is Restoring the parent stream boundary token after processing of a nested stream is left to the application. |
null , the platform
default encoding is used. |
encapsulation . |
|