Class ContentConsumer

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

class ContentConsumer extends UpdateConsumer
The ContentConsumer object represents a consumer for a multipart body part. This will read the contents of the cursor until such time as it reads the terminal boundary token, which is used to frame the content. Once the boundary token has been read this will add itself as a part to a part list. This part list can then be used with the HTTP request to examine and use the part.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Allocator
    This is used to allocate the internal buffer when required.
    private byte[]
    Represents the message boundary that terminates the part body.
    private Buffer
    This is the internal buffer used to house the part body.
    private int
    This is used to determine how many boundary tokens are read.
    private Segment
    Represents the HTTP headers that were provided for the part.
    private PartSeries
    This is the part list that this part is to be added to.
    private int
    This is used to determine if the start token had been read.
    private static final byte[]
    This represents the start of the boundary token for the body.

    Fields inherited from class org.simpleframework.http.message.UpdateConsumer

    array, finished
  • Constructor Summary

    Constructors
    Constructor
    Description
    ContentConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
    Constructor for the ContentConsumer 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.
    protected void
    This is used to push the start and boundary back on to the cursor.
    This is used to acquire the body for this HTTP entity.
    This is used to acquire the part for this HTTP entity.
    protected int
    update(byte[] array, int off, int size)
    This is used to process the bytes that have been read from the cursor.

    Methods inherited from class org.simpleframework.http.message.UpdateConsumer

    consume, isFinished

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • START

      private static final byte[] START
      This represents the start of the boundary token for the body.
    • series

      private PartSeries series
      This is the part list that this part is to be added to.
    • allocator

      private Allocator allocator
      This is used to allocate the internal buffer when required.
    • segment

      private Segment segment
      Represents the HTTP headers that were provided for the part.
    • buffer

      private Buffer buffer
      This is the internal buffer used to house the part body.
    • boundary

      private byte[] boundary
      Represents the message boundary that terminates the part body.
    • start

      private int start
      This is used to determine if the start token had been read.
    • seek

      private int seek
      This is used to determine how many boundary tokens are read.
  • Constructor Details

    • ContentConsumer

      public ContentConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
      Constructor for the ContentConsumer object. This is used to create a consumer that reads the body of a part in a multipart request body. The terminal token must be provided so that the end of the part body can be determined.
      Parameters:
      allocator - this is used to allocate the internal buffer
      segment - this represents the headers for the part body
      series - this is the part list that this body belongs in
      boundary - this is the message boundary for the body part
  • Method Details

    • getBody

      public Body getBody()
      This is used to acquire the body for this HTTP entity. 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 Part objects. Each part can then be read as an individual message.
      Returns:
      the body provided by the HTTP request message
    • getPart

      public Part getPart()
      This is used to acquire the part for this HTTP entity. This will return a part which can be used to read the content of the message, the part created contains the contents of the body and the headers associated with it.
      Returns:
      the part provided by the HTTP request message
    • 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
    • commit

      protected void commit(ByteCursor cursor) throws IOException
      This is used to push the start and boundary back on to the cursor. Pushing the boundary back on to the cursor is required to ensure that the next consumer will have valid data to read from it. Simply resetting the boundary is not enough as this can cause an infinite loop if the connection is bad.
      Overrides:
      commit in class UpdateConsumer
      Parameters:
      cursor - this is the cursor used by this consumer
      Throws:
      IOException
    • update

      protected int update(byte[] array, int off, int size) throws IOException
      This is used to process the bytes that have been read from the cursor. This will search for the boundary token within the body of the message part, when it is found this will 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
      size - this is the number of bytes within the array
      Returns:
      this returns the number of bytes overflow that is read
      Throws:
      IOException