Package org.simpleframework.http.message
Class UpdateConsumer
java.lang.Object
org.simpleframework.http.message.UpdateConsumer
- All Implemented Interfaces:
BodyConsumer
,ByteConsumer
- Direct Known Subclasses:
ChunkedConsumer
,ContentConsumer
,FixedLengthConsumer
The
UpdateConsumer
object is used to create a consumer
that is used to consume and process large bodies. Typically a large
body will be one that is delivered as part of a multipart upload
or as a large form POST. The task of the large consumer is to
consume all the bytes for the body, and reset the cursor after the
last byte that has been send with the body. This ensures that the
next character read from the cursor is the first character of a
HTTP header within the pipeline.-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Constructor for theUpdateConsumer
object.protected
UpdateConsumer
(int chunk) Constructor for theUpdateConsumer
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
commit
(ByteCursor cursor) This method can be used to commit the consumer when all data has been consumed.void
consume
(ByteCursor cursor) This method is used to consume bytes from the provided cursor.boolean
This is used to determine whether the consumer has finished reading.protected abstract 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.simpleframework.http.message.BodyConsumer
getBody
-
Field Details
-
array
protected byte[] arrayThis is an external array used to copy data between buffers. -
finished
protected boolean finishedThis is used to determine whether the consumer has finished.
-
-
Constructor Details
-
UpdateConsumer
protected UpdateConsumer()Constructor for theUpdateConsumer
object. This is used to create a consumer with a one kilobyte buffer used to read the contents from the cursor and transfer it to the buffer. -
UpdateConsumer
protected UpdateConsumer(int chunk) Constructor for theUpdateConsumer
object. This is used to create a consumer with a variable size buffer used to read the contents from the cursor and transfer it to the buffer.- Parameters:
chunk
- this is the size of the buffer used to read bytes
-
-
Method Details
-
isFinished
public boolean isFinished()This is used to determine whether the consumer has finished reading. The consumer is considered finished if it has read a terminal token or if it has exhausted the stream and can not read any more. Once finished the consumed bytes can be parsed.- Specified by:
isFinished
in interfaceByteConsumer
- Returns:
- true if the consumer has finished reading its content
-
consume
This method is used to consume bytes from the provided cursor. Consuming of bytes from the cursor should be done in such a way that it does not block. So typically only the number of ready bytes in theByteCursor
object should be read. If there are no ready bytes then this will return.- Specified by:
consume
in interfaceByteConsumer
- Parameters:
cursor
- used to consume the bytes from the HTTP pipeline- Throws:
IOException
-
commit
This method can be used to commit the consumer when all data has been consumed. It is often used to push back some data on to the cursor so that the next consumer can read valid tokens from the stream of bytes. If no commit is required then the default implementation of this will simply return quietly.- 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. Depending on the delimiter used this knows when the end of the body has been encountered. If the end is encountered this method must return the number of bytes overflow, and set the state of the consumer to finished.- 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
-