public class NioMultipartParser extends OutputStream implements org.synchronoss.cloud.nio.stream.storage.Disposable
The main class for parsing a multipart stream in an NIO mode. A new instance can be created and the
data can be written invoking the write(byte[], int, int), write(byte[]) or write(int) methods.
As data is written, the parser is identifying the various parts and notifying the client via the NioMultipartParserListener listener.
For each part the NioMultipartParser will ask the
PartBodyStreamStorageFactory for a StreamStorage where the bytes will be written.
Once the parser finished to write, it calls the close() method.
The class extends OutputStream and it can be seen as a 'splitter' where the main stream (the multipart body) is saved into different streams (one for each part).
Each individual stream can be read back by the client when it's notified about the part completion.
For more information about the events raised by the parser see NioMultipartParserListener.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size: 16Kb
The buffer size needs to be bigger than the separator.
|
static int |
DEFAULT_HEADERS_SECTION_SIZE
The default limit in bytes of the headers section.
|
static int |
DEFAULT_MAX_LEVEL_OF_NESTED_MULTIPART
Default number of nested multiparts body.
|
| Constructor and Description |
|---|
NioMultipartParser(MultipartContext multipartContext,
NioMultipartParserListener nioMultipartParserListener)
Constructs a
NioMultipartParser. |
NioMultipartParser(MultipartContext multipartContext,
NioMultipartParserListener nioMultipartParserListener,
int bufferSize)
Constructs a
NioMultipartParser with default values for the headers section size and nested multipart limit and PartBodyStreamStorageFactory. |
NioMultipartParser(MultipartContext multipartContext,
NioMultipartParserListener nioMultipartParserListener,
PartBodyStreamStorageFactory partBodyStreamStorageFactory)
Constructs a
NioMultipartParser with default values for the buffer size, headers section size and nested multipart limit, but a
custom implementation of PartBodyStreamStorageFactory. |
NioMultipartParser(MultipartContext multipartContext,
NioMultipartParserListener nioMultipartParserListener,
PartBodyStreamStorageFactory partBodyStreamStorageFactory,
int bufferSize,
int maxHeadersSectionSize,
int maxLevelOfNestedMultipart)
Constructs a
NioMultipartParser. |
public static final int DEFAULT_BUFFER_SIZE
public static final int DEFAULT_HEADERS_SECTION_SIZE
public static final int DEFAULT_MAX_LEVEL_OF_NESTED_MULTIPART
public NioMultipartParser(MultipartContext multipartContext, NioMultipartParserListener nioMultipartParserListener)
Constructs a NioMultipartParser. The default values for the buffer size, headers section size and nested multipart limit will be used.
The PartBodyStreamStorageFactory used will be the default implementation provided with the library. See DefaultPartBodyStreamStorageFactory.
multipartContext - The multipart contextnioMultipartParserListener - The listener that will be notifiedpublic NioMultipartParser(MultipartContext multipartContext, NioMultipartParserListener nioMultipartParserListener, PartBodyStreamStorageFactory partBodyStreamStorageFactory)
Constructs a NioMultipartParser with default values for the buffer size, headers section size and nested multipart limit, but a
custom implementation of PartBodyStreamStorageFactory.
multipartContext - The multipart contextnioMultipartParserListener - The listener that will be notifiedpartBodyStreamStorageFactory - The custom PartBodyStreamStorageFactory.public NioMultipartParser(MultipartContext multipartContext, NioMultipartParserListener nioMultipartParserListener, int bufferSize)
Constructs a NioMultipartParser with default values for the headers section size and nested multipart limit and PartBodyStreamStorageFactory.
It wants the size of the buffer to use.
multipartContext - The multipart contextnioMultipartParserListener - The listener that will be notifiedbufferSize - The buffer size, a strictly positive integer.
The actual buffer size used will be MultipartUtils.getBoundary(String) + 5 + bufferSize.public NioMultipartParser(MultipartContext multipartContext, NioMultipartParserListener nioMultipartParserListener, PartBodyStreamStorageFactory partBodyStreamStorageFactory, int bufferSize, int maxHeadersSectionSize, int maxLevelOfNestedMultipart)
Constructs a NioMultipartParser.
multipartContext - The multipart contextnioMultipartParserListener - The listener that will be notifiedpartBodyStreamStorageFactory - The custom PartBodyStreamStorageFactory to use.bufferSize - The buffer size, a strictly positive integer.
The actual buffer size used will be MultipartUtils.getBoundary(String) + 5 + bufferSize.maxHeadersSectionSize - The max size of the headers sectionmaxLevelOfNestedMultipart - the max number of nested multipartpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreamIOExceptionpublic boolean dispose()
dispose in interface org.synchronoss.cloud.nio.stream.storage.Disposablepublic void flush()
throws IOException
flush in interface Flushableflush in class OutputStreamIOExceptionpublic void write(int data)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] data)
throws IOException
write in class OutputStreamIOExceptionpublic void write(byte[] data,
int indexStart,
int indexEnd)
write in class OutputStreamCopyright © 2017. All rights reserved.