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
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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    FixedLengthConsumer(Allocator allocator, long limit)
    Constructor for the FixedLengthConsumer object.
  • Method Summary

    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.
    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
  • Field Details

    • allocator

      private Allocator allocator
      This is the allocator used to allocate the buffer used.
    • buffer

      private Buffer buffer
      This is the internal buffer used to accumulate the body.
    • limit

      private long limit
      This is the number of bytes to be consumed from the cursor.
  • Constructor Details

    • 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 Details

    • 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
    • append

      private void append(byte[] array, int off, int len) throws 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 an InputStream, or the text of the appended bytes can be acquired by encoding the bytes.
      Parameters:
      array - this is the array of bytes to be appended
      off - this is the start offset in the array to read from
      len - this is the number of bytes to write to the buffer
      Throws:
      IOException
    • 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