Class UpdateConsumer

java.lang.Object
org.simpleframework.http.message.UpdateConsumer
All Implemented Interfaces:
BodyConsumer, ByteConsumer
Direct Known Subclasses:
ChunkedConsumer, ContentConsumer, FixedLengthConsumer

public abstract class UpdateConsumer extends Object implements BodyConsumer
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
    Modifier and Type
    Field
    Description
    protected byte[]
    This is an external array used to copy data between buffers.
    protected boolean
    This is used to determine whether the consumer has finished.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Constructor for the UpdateConsumer object.
    protected
    UpdateConsumer(int chunk)
    Constructor for the UpdateConsumer object.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    This method can be used to commit the consumer when all data has been consumed.
    void
    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[] array
      This is an external array used to copy data between buffers.
    • finished

      protected boolean finished
      This is used to determine whether the consumer has finished.
  • Constructor Details

    • UpdateConsumer

      protected UpdateConsumer()
      Constructor for the UpdateConsumer 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 the UpdateConsumer 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 interface ByteConsumer
      Returns:
      true if the consumer has finished reading its content
    • consume

      public void consume(ByteCursor cursor) throws IOException
      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 the ByteCursor object should be read. If there are no ready bytes then this will return.
      Specified by:
      consume in interface ByteConsumer
      Parameters:
      cursor - used to consume the bytes from the HTTP pipeline
      Throws:
      IOException
    • commit

      protected void commit(ByteCursor cursor) throws IOException
      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

      protected abstract int update(byte[] array, int off, int count) throws IOException
      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 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