Package ai.djl.inference.streaming
Class ChunkedBytesSupplier
java.lang.Object
ai.djl.inference.streaming.ChunkedBytesSupplier
- All Implemented Interfaces:
BytesSupplier
A {link BytesSupplier} that supports chunked reading.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new {code ChunkedBytesSupplier} instance. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendContent(byte[] data, boolean lastChunk) Appends content to theBytesSupplier.voidappendContent(BytesSupplier bytesSupplier, boolean lastChunk) Appends content to theBytesSupplier.byte[]Returns thebyte[]presentation of the object.booleanhasNext()Returnstrueif has more chunk.Returns the next chunk.byte[]Returns the next chunk.poll()Retrieves and removes the head of chunk or returnsnullif data is not available.byte[]Retrieves and removes the head of chunk or returnsnullif data is not available.Returns theByteBufferpresentation of the object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ai.djl.ndarray.BytesSupplier
getAsObject, getAsString
-
Constructor Details
-
ChunkedBytesSupplier
public ChunkedBytesSupplier()Constructs a new {code ChunkedBytesSupplier} instance.
-
-
Method Details
-
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
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
Returns the next chunk.- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the next chunk
- Throws:
InterruptedException- if the thread is interrupted
-
nextChunk
Returns the next chunk.- Parameters:
timeout- the maximum time to waitunit- the time unit of the timeout argument- Returns:
- the next chunk
- Throws:
InterruptedException- if the thread is interrupted
-
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
Returns theByteBufferpresentation of the object.- Specified by:
toByteBufferin interfaceBytesSupplier- Returns:
- the
ByteBufferpresentation of the object
-