Class PartConsumer

java.lang.Object
org.simpleframework.http.message.PartConsumer
All Implemented Interfaces:
ByteConsumer

class PartConsumer extends Object implements ByteConsumer
The PartConsumer object is used to consume a part from a part list. A part consists of a header and a body, which can be either a simple chunk of data or another part list. This must be able to cope with either a simple body or a part list.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private BodyConsumer
    This is used to consume the body data from the part.
    private ByteConsumer
    This is the current consumer used to read from the cursor.
    private PartFactory
    This is used to determine what type the body data is.
    This is used to consume the header message of the part.
    private PartSeries
    This is used to add the consumed parts to when finished.
    private byte[]
    This is the terminal token that ends the part payload.
  • Constructor Summary

    Constructors
    Constructor
    Description
    PartConsumer(Allocator allocator, PartSeries series, byte[] terminal, long length)
    Constructor for the PartConsumer object.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This is used to consume the part body from the cursor.
    private BodyConsumer
    This is used to create a new body consumer used to consume the part body from for the list.
    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

    • body

      private BodyConsumer body
      This is used to consume the body data from the part.
    • factory

      private PartFactory factory
      This is used to determine what type the body data is.
    • series

      private PartSeries series
      This is used to add the consumed parts to when finished.
    • current

      private ByteConsumer current
      This is the current consumer used to read from the cursor.
    • terminal

      private byte[] terminal
      This is the terminal token that ends the part payload.
  • Constructor Details

    • PartConsumer

      public PartConsumer(Allocator allocator, PartSeries series, byte[] terminal, long length)
      Constructor for the PartConsumer object. This is used to create a consumer used to read the contents of a part and the boundary that terminates the content. Any parts that are created by this are added to the provided part list.
      Parameters:
      allocator - this is the allocator used to creat buffers
      series - this is the part list used to store the parts
      terminal - this is the terminal token for the part
      length - this is the length of the parent part series
  • Method Details

    • getConsumer

      private BodyConsumer getConsumer()
      This is used to create a new body consumer used to consume the part body from for the list. This will ensure that the part data is created based on the part header consumed. The types of part supported are part lists and part body.
      Returns:
      this returns a consumed for the part content
    • 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