Package org.simpleframework.http.message
Class ChunkedConsumer
- java.lang.Object
-
- org.simpleframework.http.message.UpdateConsumer
-
- org.simpleframework.http.message.ChunkedConsumer
-
- All Implemented Interfaces:
BodyConsumer
,ByteConsumer
public class ChunkedConsumer extends UpdateConsumer
TheChunkedConsumer
is reads an decodes a stream using the chunked transfer coding. This is used so that any data sent in the chunked transfer coding can be decoded. All bytes are appended to an internal buffer so that they can be read without having to parse the encoding.length := 0 read chunk-size, chunk-extension (if any) and CRLF while (chunk-size > 0) { read chunk-data and CRLF append chunk-data to entity-body length := length + chunk-size read chunk-size and CRLF } read entity-header while (entity-header not empty) { append entity-header to existing header fields read entity-header }
The above algorithm is taken from RFC 2616 section 19.4.6. This coding scheme is used in HTTP pipelines so that dynamic content, that is, content with which a length cannot be determined does not require a connection close to delimit the message body.- Author:
- Niall Gallagher
-
-
Field Summary
-
Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
-
-
Constructor Summary
Constructors Constructor Description ChunkedConsumer(org.simpleframework.common.buffer.Allocator allocator)
Constructor for theChunkedConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Body
getBody()
This is used to acquire the body that has been consumed.protected int
update(byte[] array, int off, int size)
This is used to process the bytes that have been read from the cursor.-
Methods inherited from class org.simpleframework.http.message.UpdateConsumer
commit, consume, isFinished
-
-
-
-
Constructor Detail
-
ChunkedConsumer
public ChunkedConsumer(org.simpleframework.common.buffer.Allocator allocator)
Constructor for theChunkedConsumer
object. This is used to create a consumer that reads chunked encoded data and appended that data in decoded form to an internal buffer so that it can be read in a clean decoded fromat.- Parameters:
allocator
- this is used to allocate the internal buffer
-
-
Method Detail
-
getBody
public Body getBody()
This is used to acquire the body that has been consumed. This will return a body which can be used to read the content of the message, also if the request is multipart upload then all of the parts are provided asAttachment
objects. Each part can then be read as an individual message.- Returns:
- the body that has been consumed by this instance
-
update
protected int update(byte[] array, int off, int size) throws java.io.IOException
This is used to process the bytes that have been read from the cursor. This will keep reading bytes from the stream until such time as the zero length chunk has been read from the stream. If the zero length chunk is encountered then the overflow count is returned so it can be used to reset the cursor.- Specified by:
update
in classUpdateConsumer
- Parameters:
array
- this is a chunk read from the cursoroff
- this is the offset within the array the chunk startssize
- this is the number of bytes within the array- Returns:
- this returns the number of bytes overflow that is read
- Throws:
java.io.IOException
-
-