Class FileUploadConsumer

  • All Implemented Interfaces:
    BodyConsumer, ByteConsumer

    public class FileUploadConsumer
    extends java.lang.Object
    implements BodyConsumer
    The FileUploadConsumer object is used to consume a list of parts encoded in the multipart format. This is can consume any number of parts from a cursor. Each part consumed is added to an internal part list which can be used to acquire the contents of the upload and inspect the headers provided for each uploaded part. To ensure that only a fixed number of bytes are consumed this wraps the provided cursor with a counter to ensure reads a limited amount.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private class  FileUploadConsumer.ByteCounter
      The ByteCounter is a wrapper for a cursor that can be used to restrict the number of bytes consumed.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private BodyConsumer consumer
      This is used to read and parse the contents of the part series.
      private java.util.concurrent.atomic.AtomicLong count
      This counts the number of bytes remaining the the part series.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileUploadConsumer​(Allocator allocator, byte[] boundary, long length)
      Constructor for the FileUploadConsumer object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void consume​(ByteCursor cursor)
      This method is used to consume bytes from the provided cursor.
      Body getBody()
      This is used to acquire the body that has been consumed.
      boolean isFinished()
      This is used to determine whether the consumer has finished reading.
      • Methods inherited from class java.lang.Object

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

      • consumer

        private final BodyConsumer consumer
        This is used to read and parse the contents of the part series.
      • count

        private final java.util.concurrent.atomic.AtomicLong count
        This counts the number of bytes remaining the the part series.
    • Constructor Detail

      • FileUploadConsumer

        public FileUploadConsumer​(Allocator allocator,
                                  byte[] boundary,
                                  long length)
        Constructor for the FileUploadConsumer object. This is used to create an object that read a series of parts from a fixed length body. When consuming the body this will not read any more than the content length from the cursor.
        Parameters:
        allocator - this is the allocator used to allocate buffers
        boundary - this is the boundary that is used by this
        length - this is the number of bytes for this part series
    • Method Detail

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