Class PartConsumer

  • All Implemented Interfaces:
    ByteConsumer

    class PartConsumer
    extends java.lang.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 body
      This is used to consume the body data from the part.
      private ByteConsumer current
      This is the current consumer used to read from the cursor.
      private PartFactory factory
      This is used to determine what type the body data is.
      private SegmentConsumer header
      This is used to consume the header message of the part.
      private PartSeries series
      This is used to add the consumed parts to when finished.
      private byte[] terminal
      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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void consume​(ByteCursor cursor)
      This is used to consume the part body from the cursor.
      private BodyConsumer getConsumer()
      This is used to create a new body consumer used to consume the part body from for the list.
      boolean isFinished()
      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 Detail

      • header

        private SegmentConsumer header
        This is used to consume the header message of the part.
      • 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 Detail

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

      • 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 java.io.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:
        java.io.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