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
class ContentConsumer extends UpdateConsumer
TheContentConsumer
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:
PartConsumer
-
-
Field Summary
Fields Modifier and Type Field Description private Allocator
allocator
This is used to allocate the internal buffer when required.private byte[]
boundary
Represents the message boundary that terminates the part body.private Buffer
buffer
This is the internal buffer used to house the part body.private int
seek
This is used to determine how many boundary tokens are read.private Segment
segment
Represents the HTTP headers that were provided for the part.private PartSeries
series
This is the part list that this part is to be added to.private int
start
This is used to determine if the start token had been read.private static byte[]
START
This represents the start of the boundary token for the body.-
Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
-
-
Constructor Summary
Constructors Constructor Description ContentConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
Constructor for theContentConsumer
object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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.Body
getBody()
This is used to acquire the body for this HTTP entity.Part
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 Detail
-
START
private static final byte[] START
This represents the start of the boundary token for the body.
-
series
private PartSeries series
This is the part list that this part is to be added to.
-
allocator
private Allocator allocator
This is used to allocate the internal buffer when required.
-
segment
private Segment segment
Represents the HTTP headers that were provided for the part.
-
buffer
private Buffer buffer
This is the internal buffer used to house the part body.
-
boundary
private byte[] boundary
Represents the message boundary that terminates the part body.
-
start
private int start
This is used to determine if the start token had been read.
-
seek
private int seek
This is used to determine how many boundary tokens are read.
-
-
Constructor Detail
-
ContentConsumer
public ContentConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
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 Detail
-
getBody
public Body 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
public Part 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
private void append(byte[] array, int off, int len) throws java.io.IOException
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:
java.io.IOException
-
commit
protected void commit(ByteCursor cursor) throws java.io.IOException
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:
java.io.IOException
-
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 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:
java.io.IOException
-
-