Package org.simpleframework.http.message
Class ContentConsumer
java.lang.Object
org.simpleframework.http.message.UpdateConsumer
org.simpleframework.http.message.ContentConsumer
- All Implemented Interfaces:
BodyConsumer
,ByteConsumer
The
ContentConsumer
object represents a consumer for
a multipart body part. This will read the contents of the cursor
until such time as it reads the terminal boundary token, which is
used to frame the content. Once the boundary token has been read
this will add itself as a part to a part list. This part list can
then be used with the HTTP request to examine and use the part.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Allocator
This is used to allocate the internal buffer when required.private byte[]
Represents the message boundary that terminates the part body.private Buffer
This is the internal buffer used to house the part body.private int
This is used to determine how many boundary tokens are read.private Segment
Represents the HTTP headers that were provided for the part.private PartSeries
This is the part list that this part is to be added to.private int
This is used to determine if the start token had been read.private static final byte[]
This represents the start of the boundary token for the body.Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
-
Constructor Summary
ConstructorsConstructorDescriptionContentConsumer
(Allocator allocator, Segment segment, PartSeries series, byte[] boundary) Constructor for theContentConsumer
object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
append
(byte[] array, int off, int len) This method is used to append the contents of the array to the internal buffer.protected void
commit
(ByteCursor cursor) This is used to push the start and boundary back on to the cursor.getBody()
This is used to acquire the body for this HTTP entity.getPart()
This is used to acquire the part for this HTTP entity.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
consume, isFinished
-
Field Details
-
START
private static final byte[] STARTThis represents the start of the boundary token for the body. -
series
This is the part list that this part is to be added to. -
allocator
This is used to allocate the internal buffer when required. -
segment
Represents the HTTP headers that were provided for the part. -
buffer
This is the internal buffer used to house the part body. -
boundary
private byte[] boundaryRepresents the message boundary that terminates the part body. -
start
private int startThis is used to determine if the start token had been read. -
seek
private int seekThis is used to determine how many boundary tokens are read.
-
-
Constructor Details
-
ContentConsumer
Constructor for theContentConsumer
object. This is used to create a consumer that reads the body of a part in a multipart request body. The terminal token must be provided so that the end of the part body can be determined.- Parameters:
allocator
- this is used to allocate the internal buffersegment
- this represents the headers for the part bodyseries
- this is the part list that this body belongs inboundary
- this is the message boundary for the body part
-
-
Method Details
-
getBody
This is used to acquire the body for this HTTP entity. 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 asPart
objects. Each part can then be read as an individual message.- Returns:
- the body provided by the HTTP request message
-
getPart
This is used to acquire the part for this HTTP entity. This will return a part which can be used to read the content of the message, the part created contains the contents of the body and the headers associated with it.- Returns:
- the part provided by the HTTP request message
-
append
This method is used to append the contents of the array to the internal buffer. The appended bytes can be acquired from the internal buffer using anInputStream
, or the text of the appended bytes can be acquired by encoding the bytes.- Parameters:
array
- this is the array of bytes to be appendedoff
- this is the start offset in the array to read fromlen
- this is the number of bytes to write to the buffer- Throws:
IOException
-
commit
This is used to push the start and boundary back on to the cursor. Pushing the boundary back on to the cursor is required to ensure that the next consumer will have valid data to read from it. Simply resetting the boundary is not enough as this can cause an infinite loop if the connection is bad.- Overrides:
commit
in classUpdateConsumer
- Parameters:
cursor
- this is the cursor used by this consumer- Throws:
IOException
-
update
This is used to process the bytes that have been read from the cursor. This will search for the boundary token within the body of the message part, when it is found this will returns the number of bytes that represent the overflow.- 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:
IOException
-