Class PartBodyConsumer

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

class PartBodyConsumer extends Object implements BodyConsumer
The PartBodyConsumer object is used to consume a part the contents of a multipart body. This will consume the part and add it to a part list, once the part has been consumed and added to the part list a terminal token is consumed, which is a carriage return and line feed.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This is used to consume the content from the multipart upload.
    private static final byte[]
    This is the token that is consumed after the content body.
    private ByteConsumer
    This is used to consume the final terminal token from the part.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PartBodyConsumer(Allocator allocator, Segment segment, byte[] boundary)
    Constructor for the PartBodyConsumer object.
    PartBodyConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
    Constructor for the PartBodyConsumer object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to consume the part body from the cursor.
    This is used to acquire the body that has been consumed.
    boolean
    This is used to determine whether the part body has been read from the cursor successfully.

    Methods inherited from class java.lang.Object

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

    • LINE

      private static final byte[] LINE
      This is the token that is consumed after the content body.
    • content

      private ContentConsumer content
      This is used to consume the content from the multipart upload.
    • token

      private ByteConsumer token
      This is used to consume the final terminal token from the part.
  • Constructor Details

    • PartBodyConsumer

      public PartBodyConsumer(Allocator allocator, Segment segment, byte[] boundary)
      Constructor for the PartBodyConsumer 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
      boundary - this is the message boundary for the body part
    • PartBodyConsumer

      public PartBodyConsumer(Allocator allocator, Segment segment, PartSeries series, byte[] boundary)
      Constructor for the PartBodyConsumer 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 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.
      Specified by:
      getBody in interface BodyConsumer
      Returns:
      the body that has been consumed by this instance
    • consume

      public void consume(ByteCursor cursor) throws IOException
      This is used to consume the part body from the cursor. This initially reads the body of the part, which represents the actual payload exposed via the Part interface once the payload has been consumed the terminal is consumed.
      Specified by:
      consume in interface ByteConsumer
      Parameters:
      cursor - this is the cursor to consume the body from
      Throws:
      IOException
    • isFinished

      public boolean isFinished()
      This is used to determine whether the part body has been read from the cursor successfully. In order to determine if all of the bytes have been read successfully this will check to see of the terminal token had been consumed.
      Specified by:
      isFinished in interface ByteConsumer
      Returns:
      true if the part body and terminal have been read