Top Description Fields Constructors Methods
io.netty.handler.codec.http.multipart

public Class HttpPostMultipartRequestDecoder

extends Object
implements InterfaceHttpPostRequestDecoder
Class Inheritance
All Implemented Interfaces
io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder
Imports
io.netty.buffer.ByteBuf, io.netty.handler.codec.http.HttpConstants, .HttpContent, .HttpHeaderNames, .HttpHeaderValues, .HttpRequest, .LastHttpContent, .QueryStringDecoder, io.netty.handler.codec.http.multipart.HttpPostBodyUtil.SeekAheadOptimize, .HttpPostBodyUtil.TransferEncodingMechanism, .HttpPostRequestDecoder.EndOfDataDecoderException, .HttpPostRequestDecoder.ErrorDataDecoderException, .HttpPostRequestDecoder.MultiPartStatus, .HttpPostRequestDecoder.NotEnoughDataDecoderException, io.netty.util.CharsetUtil, io.netty.util.internal.EmptyArrays, .InternalThreadLocalMap, .PlatformDependent, .StringUtil, java.io.IOException, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, java.util.ArrayList, .List, .Map, .TreeMap

This decoder will decode Body and can handle POST BODY. You MUST call destroy() after completion to release all resources.

Field Summary

Modifier and TypeField and Description
private final List<InterfaceHttpData>
bodyListHttpData

HttpDatas from Body

private int
bodyListHttpDataRank

Body HttpDatas current position

private final Map<String, List<InterfaceHttpData>>
bodyMapHttpData

HttpDatas as Map from Body

private Charset
charset

Default charset to use

private Attribute
currentAttribute

The current Attribute that is currently in decode process

private Map<CharSequence, Attribute>
currentFieldAttributes

Used in Multipart

private FileUpload
currentFileUpload

The current FileUpload that is currently in decode process

private HttpPostRequestDecoder.MultiPartStatus
currentStatus

Current getStatus

private boolean
private int
private final HttpDataFactory
factory

Factory used to create InterfaceHttpData

private static final String
private boolean
isLastChunk

Does the last chunk already received

private final String
multipartDataBoundary

If multipart, this is the boundary for the global multipart

private String
multipartMixedBoundary

If multipart, there could be internal multiparts (mixed) to the global multipart.

private final HttpRequest
request

Request to decode

private ByteBuf
undecodedChunk

The current channelBuffer

Constructor Summary

AccessConstructor and Description
public
HttpPostMultipartRequestDecoder(HttpRequest
the request to decode
request
)

public
HttpPostMultipartRequestDecoder(HttpDataFactory
the factory used to create InterfaceHttpData
factory
,
HttpRequest
the request to decode
request
)

public
HttpPostMultipartRequestDecoder(HttpDataFactory
the factory used to create InterfaceHttpData
factory
,
HttpRequest
the request to decode
request
,
Charset
the charset to use as default
charset
)

Method Summary

Modifier and TypeMethod and Description
protected void
addHttpData(InterfaceHttpData data)

Utility function to add a new decoded data

private void
public void
cleanFiles()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.cleanFiles.

Clean all HttpDatas (on Disk) for the current request.
private void
cleanMixedAttributes()

Remove all Attributes that should be cleaned between two FileUpload in Mixed mode

private static String

Returns:

the cleaned String
cleanString
(String field)

Clean the String from any unallowed character

public InterfaceHttpData
currentPartialHttpData()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.currentPartialHttpData.

Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded).
private InterfaceHttpData

Returns:

the next decoded InterfaceHttpData or null if none until now.
decodeMultipart
(HttpPostRequestDecoder.MultiPartStatus state)

Decode a multipart request by pieces NOTSTARTED PREAMBLE ( (HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))* (HEADERDELIMITER DISPOSITION MIXEDPREAMBLE (MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+ MIXEDCLOSEDELIMITER)* CLOSEDELIMITER)+ EPILOGUE Inspired from HttpMessageDecoder

public void
private InterfaceHttpData

Returns:

the next InterfaceHttpData if any
findMultipartDelimiter
(String
delimiter to find
delimiter
,
HttpPostRequestDecoder.MultiPartStatus
the next getStatus if the delimiter is a start
dispositionStatus
,
HttpPostRequestDecoder.MultiPartStatus
the next getStatus if the delimiter is a close delimiter
closeDelimiterStatus
)

Find the next Multipart Delimiter

private InterfaceHttpData

Returns:

the next InterfaceHttpData if any
findMultipartDisposition
()

Find the next Disposition

public InterfaceHttpData

Returns:

The first Body InterfaceHttpData with the given name (ignore case)
getBodyHttpData
(String name)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpData.

This getMethod returns the first InterfaceHttpData with the given name from body.
public List<InterfaceHttpData>

Returns:

the list of HttpDatas from Body part for POST getMethod
getBodyHttpDatas
()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpDatas.

This getMethod returns a List of all HttpDatas from body.
public List<InterfaceHttpData>

Returns:

All Body HttpDatas with the given name (ignore case)
getBodyHttpDatas
(String name)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpDatas.

This getMethod returns a List of all HttpDatas with the given name from body.
private Attribute
pack-priv int

Returns:

the number of bytes the internal buffer can contain
getCurrentAllocatedCapacity
()

This method is package private intentionally in order to allow during tests to access to the amount of memory allocated (capacity) within the private ByteBuf undecodedChunk

public int
getDiscardThreshold()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getDiscardThreshold.

Return the threshold in bytes after which read data in the buffer should be discarded.
protected InterfaceHttpData

Returns:

the InterfaceHttpData if any
getFileUpload
(String
the delimiter to use
delimiter
)

Get the FileUpload (new one or current one)

public boolean

Returns:

True if at current getStatus, there is a decoded InterfaceHttpData
hasNext
()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.hasNext.

True if at current getStatus, there is an available decoded InterfaceHttpData from the Body.
public boolean

Returns:

True if this request is a Multipart request
isMultipart
()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.isMultipart.

True if this request is a Multipart request
private static boolean

Returns:

true if the last chunk is loaded (boundary delimiter found), false if need more chunks
loadDataMultipartOptimized
(ByteBuf undecodedChunk, String delimiter, HttpData httpData)

Load the field value or file data from a Multipart request

public InterfaceHttpData

Returns:

the next available InterfaceHttpData or null if none
next
()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.next.

Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData.
public HttpPostMultipartRequestDecoder
offer(HttpContent
the new received chunk
content
)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.offer.

Initialized the internals from a new chunk
private void
parseBody()

This getMethod will parse as much as possible data and fill the list and map

private void
parseBodyMultipart()

Parse the Body for multipart

private static String

Returns:

the String from one line as the delimiter searched (opening or closing)
readDelimiterOptimized
(ByteBuf undecodedChunk, String
of the form --string, such that '--' is already included
delimiter
,
Charset charset)

Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF.

private static String

Returns:

the String from one line
readLineOptimized
(ByteBuf undecodedChunk, Charset charset)

Read one line up to the CRLF or LF

public void
private static void
rewriteCurrentBuffer(ByteBuf
the buffer to rewrite from current readerIndex
buffer
,
int
the size to skip from readerIndex
lengthToSkip
)

Rewrite buffer in order to skip lengthToSkip bytes from current readerIndex, such that any readable bytes available after readerIndex + lengthToSkip (so before writerIndex) are moved at readerIndex position, therefore decreasing writerIndex of lengthToSkip at the end of the process.

public void
setDiscardThreshold(int discardThreshold)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.setDiscardThreshold.

Set the amount of bytes after which read bytes in the buffer should be discarded.
private static void
skipControlCharacters(ByteBuf undecodedChunk)

Skip control Characters

private static void
private boolean

Returns:

True if one empty line was skipped
skipOneLine
()

Skip one empty line

private static String[]

Returns:

an array of String where rank 0 is the name of the header, follows by several values that were separated by ';' or ','
splitMultipartHeader
(String sb)

Split one header in Multipart

private static String[]

Returns:

an array of String where values that were separated by ';' or ','
splitMultipartHeaderValues
(String svalue)

Split one header value in Multipart

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bodyListHttpDataback to summary
private final List<InterfaceHttpData> bodyListHttpData

HttpDatas from Body

bodyListHttpDataRankback to summary
private int bodyListHttpDataRank

Body HttpDatas current position

bodyMapHttpDataback to summary
private final Map<String, List<InterfaceHttpData>> bodyMapHttpData

HttpDatas as Map from Body

charsetback to summary
private Charset charset

Default charset to use

currentAttributeback to summary
private Attribute currentAttribute

The current Attribute that is currently in decode process

currentFieldAttributesback to summary
private Map<CharSequence, Attribute> currentFieldAttributes

Used in Multipart

currentFileUploadback to summary
private FileUpload currentFileUpload

The current FileUpload that is currently in decode process

currentStatusback to summary
private HttpPostRequestDecoder.MultiPartStatus currentStatus

Current getStatus

destroyedback to summary
private boolean destroyed
discardThresholdback to summary
private int discardThreshold
factoryback to summary
private final HttpDataFactory factory

Factory used to create InterfaceHttpData

FILENAME_ENCODEDback to summary
private static final String FILENAME_ENCODED
isLastChunkback to summary
private boolean isLastChunk

Does the last chunk already received

multipartDataBoundaryback to summary
private final String multipartDataBoundary

If multipart, this is the boundary for the global multipart

multipartMixedBoundaryback to summary
private String multipartMixedBoundary

If multipart, there could be internal multiparts (mixed) to the global multipart. Only one level is allowed.

requestback to summary
private final HttpRequest request

Request to decode

undecodedChunkback to summary
private ByteBuf undecodedChunk

The current channelBuffer

Constructor Detail

HttpPostMultipartRequestDecoderback to summary
public HttpPostMultipartRequestDecoder(HttpRequest request)
Parameters
request:HttpRequest

the request to decode

Exceptions
NullPointerException:
for request
ErrorDataDecoderException:
if the default charset was wrong when decoding or other errors
HttpPostMultipartRequestDecoderback to summary
public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request)
Parameters
factory:HttpDataFactory

the factory used to create InterfaceHttpData

request:HttpRequest

the request to decode

Exceptions
NullPointerException:
for request or factory
ErrorDataDecoderException:
if the default charset was wrong when decoding or other errors
HttpPostMultipartRequestDecoderback to summary
public HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, Charset charset)
Parameters
factory:HttpDataFactory

the factory used to create InterfaceHttpData

request:HttpRequest

the request to decode

charset:Charset

the charset to use as default

Exceptions
NullPointerException:
for request or charset or factory
ErrorDataDecoderException:
if the default charset was wrong when decoding or other errors

Method Detail

addHttpDataback to summary
protected void addHttpData(InterfaceHttpData data)

Utility function to add a new decoded data

checkDestroyedback to summary
private void checkDestroyed()
cleanFilesback to summary
public void cleanFiles()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.cleanFiles.

Clean all HttpDatas (on Disk) for the current request.

Annotations
@Override
cleanMixedAttributesback to summary
private void cleanMixedAttributes()

Remove all Attributes that should be cleaned between two FileUpload in Mixed mode

cleanStringback to summary
private static String cleanString(String field)

Clean the String from any unallowed character

Returns:String

the cleaned String

currentPartialHttpDataback to summary
public InterfaceHttpData currentPartialHttpData()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.currentPartialHttpData.

Doc from io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.currentPartialHttpData.

Returns the current InterfaceHttpData if currently in decoding status, meaning all data are not yet within, or null if there is no InterfaceHttpData currently in decoding status (either because none yet decoded or none currently partially decoded). Full decoded ones are accessible through hasNext() and next() methods.

Returns:InterfaceHttpData

the current InterfaceHttpData if currently in decoding status or null if none.

Annotations
@Override
decodeMultipartback to summary
private InterfaceHttpData decodeMultipart(HttpPostRequestDecoder.MultiPartStatus state)

Decode a multipart request by pieces

NOTSTARTED PREAMBLE (
(HEADERDELIMITER DISPOSITION (FIELD | FILEUPLOAD))*
(HEADERDELIMITER DISPOSITION MIXEDPREAMBLE
(MIXEDDELIMITER MIXEDDISPOSITION MIXEDFILEUPLOAD)+
MIXEDCLOSEDELIMITER)*
CLOSEDELIMITER)+ EPILOGUE
Inspired from HttpMessageDecoder

Returns:InterfaceHttpData

the next decoded InterfaceHttpData or null if none until now.

Exceptions
ErrorDataDecoderException:
if an error occurs
destroyback to summary
public void destroy()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.destroy.

Destroy the HttpPostMultipartRequestDecoder and release all it resources. After this method was called it is not possible to operate on it anymore.

Annotations
@Override
findMultipartDelimiterback to summary
private InterfaceHttpData findMultipartDelimiter(String delimiter, HttpPostRequestDecoder.MultiPartStatus dispositionStatus, HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus)

Find the next Multipart Delimiter

Parameters
delimiter:String

delimiter to find

dispositionStatus:HttpPostRequestDecoder.MultiPartStatus

the next getStatus if the delimiter is a start

closeDelimiterStatus:HttpPostRequestDecoder.MultiPartStatus

the next getStatus if the delimiter is a close delimiter

Returns:InterfaceHttpData

the next InterfaceHttpData if any

findMultipartDispositionback to summary
private InterfaceHttpData findMultipartDisposition()

Find the next Disposition

Returns:InterfaceHttpData

the next InterfaceHttpData if any

getBodyHttpDataback to summary
public InterfaceHttpData getBodyHttpData(String name)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpData.

This getMethod returns the first InterfaceHttpData with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.

Returns:InterfaceHttpData

The first Body InterfaceHttpData with the given name (ignore case)

Annotations
@Override
Exceptions
NotEnoughDataDecoderException:
need more chunks
getBodyHttpDatasback to summary
public List<InterfaceHttpData> getBodyHttpDatas()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpDatas.

This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.

Returns:List<InterfaceHttpData>

the list of HttpDatas from Body part for POST getMethod

Annotations
@Override
Exceptions
NotEnoughDataDecoderException:
Need more chunks
getBodyHttpDatasback to summary
public List<InterfaceHttpData> getBodyHttpDatas(String name)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getBodyHttpDatas.

This getMethod returns a List of all HttpDatas with the given name from body.
If chunked, all chunks must have been offered using offer() getMethod. If not, NotEnoughDataDecoderException will be raised.

Returns:List<InterfaceHttpData>

All Body HttpDatas with the given name (ignore case)

Annotations
@Override
Exceptions
NotEnoughDataDecoderException:
need more chunks
getContentDispositionAttributeback to summary
private Attribute getContentDispositionAttribute(String... values)
getCurrentAllocatedCapacityback to summary
pack-priv int getCurrentAllocatedCapacity()

This method is package private intentionally in order to allow during tests to access to the amount of memory allocated (capacity) within the private ByteBuf undecodedChunk

Returns:int

the number of bytes the internal buffer can contain

getDiscardThresholdback to summary
public int getDiscardThreshold()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.getDiscardThreshold.

Return the threshold in bytes after which read data in the buffer should be discarded.

Annotations
@Override
getFileUploadback to summary
protected InterfaceHttpData getFileUpload(String delimiter)

Get the FileUpload (new one or current one)

Parameters
delimiter:String

the delimiter to use

Returns:InterfaceHttpData

the InterfaceHttpData if any

hasNextback to summary
public boolean hasNext()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.hasNext.

True if at current getStatus, there is an available decoded InterfaceHttpData from the Body. This getMethod works for chunked and not chunked request.

Returns:boolean

True if at current getStatus, there is a decoded InterfaceHttpData

Annotations
@Override
Exceptions
EndOfDataDecoderException:
No more data will be available
isMultipartback to summary
public boolean isMultipart()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.isMultipart.

True if this request is a Multipart request

Returns:boolean

True if this request is a Multipart request

Annotations
@Override
loadDataMultipartOptimizedback to summary
private static boolean loadDataMultipartOptimized(ByteBuf undecodedChunk, String delimiter, HttpData httpData)

Load the field value or file data from a Multipart request

Returns:boolean

true if the last chunk is loaded (boundary delimiter found), false if need more chunks

nextback to summary
public InterfaceHttpData next()

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.next.

Returns the next available InterfaceHttpData or null if, at the time it is called, there is no more available InterfaceHttpData. A subsequent call to offer(httpChunk) could enable more data. Be sure to call InterfaceHttpData#release() after you are done with processing to make sure to not leak any resources

Returns:InterfaceHttpData

the next available InterfaceHttpData or null if none

Annotations
@Override
Exceptions
EndOfDataDecoderException:
No more data will be available
offerback to summary
public HttpPostMultipartRequestDecoder offer(HttpContent content)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.offer.

Initialized the internals from a new chunk

Parameters
content:HttpContent

the new received chunk

Annotations
@Override
Exceptions
ErrorDataDecoderException:
if there is a problem with the charset decoding or other errors
parseBodyback to summary
private void parseBody()

This getMethod will parse as much as possible data and fill the list and map

Exceptions
ErrorDataDecoderException:
if there is a problem with the charset decoding or other errors
parseBodyMultipartback to summary
private void parseBodyMultipart()

Parse the Body for multipart

Exceptions
ErrorDataDecoderException:
if there is a problem with the charset decoding or other errors
readDelimiterOptimizedback to summary
private static String readDelimiterOptimized(ByteBuf undecodedChunk, String delimiter, Charset charset)

Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF Read one line up to --delimiter or --delimiter-- and if existing the CRLF or LF. Note that CRLF or LF are mandatory for opening delimiter (--delimiter) but not for closing delimiter (--delimiter--) since some clients does not include CRLF in this case.

Parameters
delimiter:String

of the form --string, such that '--' is already included

Returns:String

the String from one line as the delimiter searched (opening or closing)

Exceptions
NotEnoughDataDecoderException:
Need more chunks and reset the readerIndex to the previous value
readLineOptimizedback to summary
private static String readLineOptimized(ByteBuf undecodedChunk, Charset charset)

Read one line up to the CRLF or LF

Returns:String

the String from one line

Exceptions
NotEnoughDataDecoderException:
Need more chunks and reset the readerIndex to the previous value
removeHttpDataFromCleanback to summary
public void removeHttpDataFromClean(InterfaceHttpData data)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.removeHttpDataFromClean.

Remove the given FileUpload from the list of FileUploads to clean

Annotations
@Override
rewriteCurrentBufferback to summary
private static void rewriteCurrentBuffer(ByteBuf buffer, int lengthToSkip)

Rewrite buffer in order to skip lengthToSkip bytes from current readerIndex, such that any readable bytes available after readerIndex + lengthToSkip (so before writerIndex) are moved at readerIndex position, therefore decreasing writerIndex of lengthToSkip at the end of the process.

Parameters
buffer:ByteBuf

the buffer to rewrite from current readerIndex

lengthToSkip:int

the size to skip from readerIndex

setDiscardThresholdback to summary
public void setDiscardThreshold(int discardThreshold)

Implements io.netty.handler.codec.http.multipart.InterfaceHttpPostRequestDecoder.setDiscardThreshold.

Set the amount of bytes after which read bytes in the buffer should be discarded. Setting this lower gives lower memory usage but with the overhead of more memory copies. Use 0 to disable it.

Annotations
@Override
skipControlCharactersback to summary
private static void skipControlCharacters(ByteBuf undecodedChunk)

Skip control Characters

skipControlCharactersStandardback to summary
private static void skipControlCharactersStandard(ByteBuf undecodedChunk)
skipOneLineback to summary
private boolean skipOneLine()

Skip one empty line

Returns:boolean

True if one empty line was skipped

splitMultipartHeaderback to summary
private static String[] splitMultipartHeader(String sb)

Split one header in Multipart

Returns:String[]

an array of String where rank 0 is the name of the header, follows by several values that were separated by ';' or ','

splitMultipartHeaderValuesback to summary
private static String[] splitMultipartHeaderValues(String svalue)

Split one header value in Multipart

Returns:String[]

an array of String where values that were separated by ';' or ','