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
public class FixedLengthConsumer extends UpdateConsumer
TheFixedLengthConsumer
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.- Author:
- Niall Gallagher
-
-
Field Summary
-
Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
-
-
Constructor Summary
Constructors Constructor Description FixedLengthConsumer(org.simpleframework.common.buffer.Allocator allocator, long limit)
Constructor for theFixedLengthConsumer
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 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
-
-
-
-
Constructor Detail
-
FixedLengthConsumer
public FixedLengthConsumer(org.simpleframework.common.buffer.Allocator allocator, long limit)
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 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 count) throws java.io.IOException
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:
java.io.IOException
-
-