Class ChunkedBytesSupplier

  • All Implemented Interfaces:
    BytesSupplier

    public class ChunkedBytesSupplier
    extends java.lang.Object
    implements BytesSupplier
    A {link BytesSupplier} that supports chunked reading.
    • Constructor Summary

      Constructors 
      Constructor Description
      ChunkedBytesSupplier()
      Constructs a new {code ChunkedBytesSupplier} instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void appendContent​(byte[] data, boolean lastChunk)
      Appends content to the BytesSupplier.
      void appendContent​(BytesSupplier bytesSupplier, boolean lastChunk)
      Appends content to the BytesSupplier.
      byte[] getAsBytes()
      Returns the byte[] presentation of the object.
      boolean hasNext()
      Returns true if has more chunk.
      BytesSupplier next​(long timeout, java.util.concurrent.TimeUnit unit)
      Returns the next chunk.
      byte[] nextChunk​(long timeout, java.util.concurrent.TimeUnit unit)
      Returns the next chunk.
      BytesSupplier poll()
      Retrieves and removes the head of chunk or returns null if data is not available.
      byte[] pollChunk()
      Retrieves and removes the head of chunk or returns null if data is not available.
      java.nio.ByteBuffer toByteBuffer()
      Returns the ByteBuffer presentation of the object.
      • Methods inherited from class java.lang.Object

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

      • ChunkedBytesSupplier

        public ChunkedBytesSupplier()
        Constructs a new {code ChunkedBytesSupplier} instance.
    • Method Detail

      • appendContent

        public void appendContent​(byte[] data,
                                  boolean lastChunk)
        Appends content to the BytesSupplier.
        Parameters:
        data - bytes to append
        lastChunk - true if this is the last chunk
      • appendContent

        public void appendContent​(BytesSupplier bytesSupplier,
                                  boolean lastChunk)
        Appends content to the BytesSupplier.
        Parameters:
        bytesSupplier - BytesSupplier to append
        lastChunk - true if this is the last chunk
      • hasNext

        public boolean hasNext()
        Returns true if has more chunk.
        Returns:
        true if has more chunk
      • next

        public BytesSupplier next​(long timeout,
                                  java.util.concurrent.TimeUnit unit)
                           throws java.lang.InterruptedException
        Returns the next chunk.
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        the next chunk
        Throws:
        java.lang.InterruptedException - if the thread is interrupted
      • nextChunk

        public byte[] nextChunk​(long timeout,
                                java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException
        Returns the next chunk.
        Parameters:
        timeout - the maximum time to wait
        unit - the time unit of the timeout argument
        Returns:
        the next chunk
        Throws:
        java.lang.InterruptedException - if the thread is interrupted
      • poll

        public BytesSupplier poll()
        Retrieves and removes the head of chunk or returns null if data is not available.
        Returns:
        the head of chunk or returns null if data is not available
      • pollChunk

        public byte[] pollChunk()
        Retrieves and removes the head of chunk or returns null if data is not available.
        Returns:
        the head of chunk or returns null if data is not available
      • getAsBytes

        public byte[] getAsBytes()
        Returns the byte[] presentation of the object.
        Specified by:
        getAsBytes in interface BytesSupplier
        Returns:
        the byte[] presentation of the object
      • toByteBuffer

        public java.nio.ByteBuffer toByteBuffer()
        Returns the ByteBuffer presentation of the object.
        Specified by:
        toByteBuffer in interface BytesSupplier
        Returns:
        the ByteBuffer presentation of the object