Class ChunkedBytesSupplier

java.lang.Object
ai.djl.inference.streaming.ChunkedBytesSupplier
All Implemented Interfaces:
BytesSupplier

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

    • ChunkedBytesSupplier

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

    • 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, TimeUnit unit) throws 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:
      InterruptedException - if the thread is interrupted
    • nextChunk

      public byte[] nextChunk(long timeout, TimeUnit unit) throws 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:
      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 ByteBuffer toByteBuffer()
      Returns the ByteBuffer presentation of the object.
      Specified by:
      toByteBuffer in interface BytesSupplier
      Returns:
      the ByteBuffer presentation of the object