public class HttpPostMultipartRequestDecoder extends java.lang.Object implements InterfaceHttpPostRequestDecoder
destroy()
after completion to release all resources.Modifier and Type | Field and Description |
---|---|
private java.util.List<InterfaceHttpData> |
bodyListHttpData
HttpDatas from Body
|
private int |
bodyListHttpDataRank
Body HttpDatas current position
|
private java.util.Map<java.lang.String,java.util.List<InterfaceHttpData>> |
bodyMapHttpData
HttpDatas as Map from Body
|
private java.nio.charset.Charset |
charset
Default charset to use
|
private Attribute |
currentAttribute
The current Attribute that is currently in decode process
|
private java.util.Map<java.lang.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 |
destroyed |
private int |
discardThreshold |
private HttpDataFactory |
factory
Factory used to create InterfaceHttpData
|
private boolean |
isLastChunk
Does the last chunk already received
|
private java.lang.String |
multipartDataBoundary
If multipart, this is the boundary for the flobal multipart
|
private java.lang.String |
multipartMixedBoundary
If multipart, there could be internal multiparts (mixed) to the global
multipart.
|
private HttpRequest |
request
Request to decode
|
private ByteBuf |
undecodedChunk
The current channelBuffer
|
Constructor and Description |
---|
HttpPostMultipartRequestDecoder(HttpDataFactory factory,
HttpRequest request) |
HttpPostMultipartRequestDecoder(HttpDataFactory factory,
HttpRequest request,
java.nio.charset.Charset charset) |
HttpPostMultipartRequestDecoder(HttpRequest request) |
Modifier and Type | Method and Description |
---|---|
protected void |
addHttpData(InterfaceHttpData data)
Utility function to add a new decoded data
|
private void |
checkDestroyed() |
void |
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 java.lang.String |
cleanString(java.lang.String field)
Clean the String from any unallowed character
|
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 |
void |
destroy()
Destroy the
HttpPostMultipartRequestDecoder and release all it resources. |
private InterfaceHttpData |
findMultipartDelimiter(java.lang.String delimiter,
HttpPostRequestDecoder.MultiPartStatus dispositionStatus,
HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus)
Find the next Multipart Delimiter
|
private InterfaceHttpData |
findMultipartDisposition()
Find the next Disposition
|
InterfaceHttpData |
getBodyHttpData(java.lang.String name)
This getMethod returns the first InterfaceHttpData with the given name from
body.
If chunked, all chunks must have been offered using offer() getMethod. |
java.util.List<InterfaceHttpData> |
getBodyHttpDatas()
This getMethod returns a List of all HttpDatas from body.
If chunked, all chunks must have been offered using offer() getMethod. |
java.util.List<InterfaceHttpData> |
getBodyHttpDatas(java.lang.String name)
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. |
int |
getDiscardThreshold()
Return the threshold in bytes after which read data in the buffer should be discarded.
|
protected InterfaceHttpData |
getFileUpload(java.lang.String delimiter)
Get the FileUpload (new one or current one)
|
boolean |
hasNext()
True if at current getStatus, there is an available decoded
InterfaceHttpData from the Body.
|
boolean |
isMultipart()
True if this request is a Multipart request
|
private void |
loadFieldMultipart(java.lang.String delimiter)
Load the field value from a Multipart request
|
private void |
loadFieldMultipartStandard(java.lang.String delimiter)
Load the field value from a Multipart request
|
InterfaceHttpData |
next()
Returns the next available InterfaceHttpData or null if, at the time it
is called, there is no more available InterfaceHttpData.
|
HttpPostMultipartRequestDecoder |
offer(HttpContent content)
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 java.lang.String |
readDelimiter(java.lang.String delimiter)
Read one line up to --delimiter or --delimiter-- and if existing the CRLF
or LF.
|
private java.lang.String |
readDelimiterStandard(java.lang.String delimiter)
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 void |
readFileUploadByteMultipart(java.lang.String delimiter)
Read a FileUpload data as Byte (Binary) and add the bytes directly to the
FileUpload.
|
private void |
readFileUploadByteMultipartStandard(java.lang.String delimiter)
Read a FileUpload data as Byte (Binary) and add the bytes directly to the
FileUpload.
|
private java.lang.String |
readLine()
Read one line up to the CRLF or LF
|
private java.lang.String |
readLineStandard()
Read one line up to the CRLF or LF
|
void |
removeHttpDataFromClean(InterfaceHttpData data)
Remove the given FileUpload from the list of FileUploads to clean
|
void |
setDiscardThreshold(int discardThreshold)
Set the amount of bytes after which read bytes in the buffer should be discarded.
|
private void |
setMultipart(java.lang.String contentType)
Set from the request ContentType the multipartDataBoundary and the possible charset.
|
(package private) void |
skipControlCharacters()
Skip control Characters
|
(package private) void |
skipControlCharactersStandard() |
private boolean |
skipOneLine()
Skip one empty line
|
private static java.lang.String[] |
splitMultipartHeader(java.lang.String sb)
Split one header in Multipart
|
private static java.lang.String[] |
splitMultipartHeaderValues(java.lang.String svalue)
Split one header value in Multipart
|
private final HttpDataFactory factory
private final HttpRequest request
private java.nio.charset.Charset charset
private boolean isLastChunk
private final java.util.List<InterfaceHttpData> bodyListHttpData
private final java.util.Map<java.lang.String,java.util.List<InterfaceHttpData>> bodyMapHttpData
private ByteBuf undecodedChunk
private int bodyListHttpDataRank
private java.lang.String multipartDataBoundary
private java.lang.String multipartMixedBoundary
private HttpPostRequestDecoder.MultiPartStatus currentStatus
private java.util.Map<java.lang.CharSequence,Attribute> currentFieldAttributes
private FileUpload currentFileUpload
private Attribute currentAttribute
private boolean destroyed
private int discardThreshold
public HttpPostMultipartRequestDecoder(HttpRequest request)
request
- the request to decodejava.lang.NullPointerException
- for requestHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other
errorspublic HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request)
factory
- the factory used to create InterfaceHttpDatarequest
- the request to decodejava.lang.NullPointerException
- for request or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other
errorspublic HttpPostMultipartRequestDecoder(HttpDataFactory factory, HttpRequest request, java.nio.charset.Charset charset)
factory
- the factory used to create InterfaceHttpDatarequest
- the request to decodecharset
- the charset to use as defaultjava.lang.NullPointerException
- for request or charset or factoryHttpPostRequestDecoder.ErrorDataDecoderException
- if the default charset was wrong when decoding or other
errorsprivate void setMultipart(java.lang.String contentType)
private void checkDestroyed()
public boolean isMultipart()
isMultipart
in interface InterfaceHttpPostRequestDecoder
public void setDiscardThreshold(int discardThreshold)
0
to disable it.setDiscardThreshold
in interface InterfaceHttpPostRequestDecoder
public int getDiscardThreshold()
getDiscardThreshold
in interface InterfaceHttpPostRequestDecoder
public java.util.List<InterfaceHttpData> getBodyHttpDatas()
getBodyHttpDatas
in interface InterfaceHttpPostRequestDecoder
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunkspublic java.util.List<InterfaceHttpData> getBodyHttpDatas(java.lang.String name)
getBodyHttpDatas
in interface InterfaceHttpPostRequestDecoder
HttpPostRequestDecoder.NotEnoughDataDecoderException
- need more chunkspublic InterfaceHttpData getBodyHttpData(java.lang.String name)
getBodyHttpData
in interface InterfaceHttpPostRequestDecoder
HttpPostRequestDecoder.NotEnoughDataDecoderException
- need more chunkspublic HttpPostMultipartRequestDecoder offer(HttpContent content)
offer
in interface InterfaceHttpPostRequestDecoder
content
- the new received chunkHttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other
errorspublic boolean hasNext()
hasNext
in interface InterfaceHttpPostRequestDecoder
HttpPostRequestDecoder.EndOfDataDecoderException
- No more data will be availablepublic InterfaceHttpData next()
ReferenceCounted.release()
after you are done
with processing to make sure to not leak any resourcesnext
in interface InterfaceHttpPostRequestDecoder
HttpPostRequestDecoder.EndOfDataDecoderException
- No more data will be availableprivate void parseBody()
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other
errorsprotected void addHttpData(InterfaceHttpData data)
private void parseBodyMultipart()
HttpPostRequestDecoder.ErrorDataDecoderException
- if there is a problem with the charset decoding or other
errorsprivate InterfaceHttpData decodeMultipart(HttpPostRequestDecoder.MultiPartStatus state)
HttpPostRequestDecoder.ErrorDataDecoderException
- if an error occursvoid skipControlCharacters()
void skipControlCharactersStandard()
private InterfaceHttpData findMultipartDelimiter(java.lang.String delimiter, HttpPostRequestDecoder.MultiPartStatus dispositionStatus, HttpPostRequestDecoder.MultiPartStatus closeDelimiterStatus)
delimiter
- delimiter to finddispositionStatus
- the next getStatus if the delimiter is a startcloseDelimiterStatus
- the next getStatus if the delimiter is a close delimiterHttpPostRequestDecoder.ErrorDataDecoderException
private InterfaceHttpData findMultipartDisposition()
HttpPostRequestDecoder.ErrorDataDecoderException
protected InterfaceHttpData getFileUpload(java.lang.String delimiter)
delimiter
- the delimiter to useHttpPostRequestDecoder.ErrorDataDecoderException
public void destroy()
HttpPostMultipartRequestDecoder
and release all it resources. After this method
was called it is not possible to operate on it anymore.destroy
in interface InterfaceHttpPostRequestDecoder
public void cleanFiles()
cleanFiles
in interface InterfaceHttpPostRequestDecoder
public void removeHttpDataFromClean(InterfaceHttpData data)
removeHttpDataFromClean
in interface InterfaceHttpPostRequestDecoder
private void cleanMixedAttributes()
private java.lang.String readLineStandard()
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous
valueprivate java.lang.String readLine()
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous
valueprivate java.lang.String readDelimiterStandard(java.lang.String delimiter)
delimiter
- of the form --string, such that '--' is already includedHttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous
valueprivate java.lang.String readDelimiter(java.lang.String delimiter)
delimiter
- of the form --string, such that '--' is already includedHttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks and reset the readerInder to the previous
valueprivate void readFileUploadByteMultipartStandard(java.lang.String delimiter)
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks but do not reset the readerInder since some
values will be already added to the FileOutputHttpPostRequestDecoder.ErrorDataDecoderException
- write IO error occurs with the FileUploadprivate void readFileUploadByteMultipart(java.lang.String delimiter)
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunks but do not reset the readerInder since some
values will be already added to the FileOutputHttpPostRequestDecoder.ErrorDataDecoderException
- write IO error occurs with the FileUploadprivate void loadFieldMultipartStandard(java.lang.String delimiter)
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunksHttpPostRequestDecoder.ErrorDataDecoderException
private void loadFieldMultipart(java.lang.String delimiter)
HttpPostRequestDecoder.NotEnoughDataDecoderException
- Need more chunksHttpPostRequestDecoder.ErrorDataDecoderException
private static java.lang.String cleanString(java.lang.String field)
private boolean skipOneLine()
private static java.lang.String[] splitMultipartHeader(java.lang.String sb)
private static java.lang.String[] splitMultipartHeaderValues(java.lang.String svalue)