org.simpleframework.http.message
Class FixedLengthConsumer

java.lang.Object
  extended by org.simpleframework.http.message.UpdateConsumer
      extended by org.simpleframework.http.message.FixedLengthConsumer
All Implemented Interfaces:
BodyConsumer, ByteConsumer

public class FixedLengthConsumer
extends UpdateConsumer

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.

Author:
Niall Gallagher

Field Summary
 
Fields inherited from class org.simpleframework.http.message.UpdateConsumer
array, finished
 
Constructor Summary
FixedLengthConsumer(Allocator allocator, long limit)
          Constructor for the FixedLengthConsumer object.
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedLengthConsumer

public FixedLengthConsumer(Allocator allocator,
                           long limit)
Constructor for the FixedLengthConsumer 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 buffer
limit - 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 as Attachment 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 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 class UpdateConsumer
Parameters:
array - this is a chunk read from the cursor
off - this is the offset within the array the chunk starts
count - this is the number of bytes within the array
Returns:
this returns the number of bytes overflow that is read
Throws:
IOException


Copyright © 2014. All Rights Reserved.