Package org.simpleframework.http.message
Class FixedLengthConsumer
java.lang.Object
org.simpleframework.http.message.UpdateConsumer
org.simpleframework.http.message.FixedLengthConsumer
- All Implemented Interfaces:
BodyConsumer
,ByteConsumer
The
FixedLengthConsumer
object reads a fixed number of
bytes from a cursor. This is typically used when the Content-Length
header is used as the body delimiter. In order to determine when
the full body has been consumed this counts the bytes read. Once
all the bytes have been read any overflow will be reset. All of the
bytes read are appended to the internal buffer so they can be read.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Allocator
This is the allocator used to allocate the buffer used.private Buffer
This is the internal buffer used to accumulate the body.private long
This is the number of bytes to be consumed from the cursor.Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
-
Constructor Summary
ConstructorsConstructorDescriptionFixedLengthConsumer
(Allocator allocator, long limit) Constructor for theFixedLengthConsumer
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.getBody()
This is used to acquire the body that has been consumed.protected int
update
(byte[] array, int off, int count) 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
-
Field Details
-
allocator
This is the allocator used to allocate the buffer used. -
buffer
This is the internal buffer used to accumulate the body. -
limit
private long limitThis is the number of bytes to be consumed from the cursor.
-
-
Constructor Details
-
FixedLengthConsumer
Constructor for theFixedLengthConsumer
object. This is used to create a consumer that reads a fixed number of bytes from a cursor and accumulates those bytes in an internal buffer so that it can be read at a later stage.- Parameters:
allocator
- this is used to allocate the internal bufferlimit
- this is the number of bytes that are to be read
-
-
Method Details
-
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
-
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
-
update
This is used to process the bytes that have been read from the cursor. This will count the number of bytes read, once all of the bytes that form the body have been read this 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 startscount
- this is the number of bytes within the array- Returns:
- this returns the number of bytes overflow that is read
- Throws:
IOException
-