Package ai.djl.inference.streaming
Class ChunkedBytesSupplier
- java.lang.Object
-
- ai.djl.inference.streaming.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 voidappendContent(byte[] data, boolean lastChunk)Appends content to theBytesSupplier.voidappendContent(BytesSupplier bytesSupplier, boolean lastChunk)Appends content to theBytesSupplier.byte[]getAsBytes()Returns thebyte[]presentation of the object.booleanhasNext()Returnstrueif has more chunk.BytesSuppliernext(long timeout, java.util.concurrent.TimeUnit unit)Returns the next chunk.byte[]nextChunk(long timeout, java.util.concurrent.TimeUnit unit)Returns the next chunk.BytesSupplierpoll()Retrieves and removes the head of chunk or returnsnullif data is not available.byte[]pollChunk()Retrieves and removes the head of chunk or returnsnullif data is not available.java.nio.ByteBuffertoByteBuffer()Returns theByteBufferpresentation of the object.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ai.djl.ndarray.BytesSupplier
getAsObject, getAsString
-
-
-
-
Method Detail
-
appendContent
public void appendContent(byte[] data, boolean lastChunk)Appends content to theBytesSupplier.- Parameters:
data- bytes to appendlastChunk- true if this is the last chunk
-
appendContent
public void appendContent(BytesSupplier bytesSupplier, boolean lastChunk)
Appends content to theBytesSupplier.- Parameters:
bytesSupplier- BytesSupplier to appendlastChunk- true if this is the last chunk
-
hasNext
public boolean hasNext()
Returnstrueif has more chunk.- Returns:
trueif 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 waitunit- 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.InterruptedExceptionReturns the next chunk.- Parameters:
timeout- the maximum time to waitunit- 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 returnsnullif data is not available.- Returns:
- the head of chunk or returns
nullif data is not available
-
pollChunk
public byte[] pollChunk()
Retrieves and removes the head of chunk or returnsnullif data is not available.- Returns:
- the head of chunk or returns
nullif data is not available
-
getAsBytes
public byte[] getAsBytes()
Returns thebyte[]presentation of the object.- Specified by:
getAsBytesin interfaceBytesSupplier- Returns:
- the
byte[]presentation of the object
-
toByteBuffer
public java.nio.ByteBuffer toByteBuffer()
Returns theByteBufferpresentation of the object.- Specified by:
toByteBufferin interfaceBytesSupplier- Returns:
- the
ByteBufferpresentation of the object
-
-