Package ai.djl.inference.streaming
Class PublisherBytesSupplier
- java.lang.Object
-
- ai.djl.inference.streaming.PublisherBytesSupplier
-
- All Implemented Interfaces:
BytesSupplier
public class PublisherBytesSupplier extends java.lang.Object implements BytesSupplier
AnPublisherBytesSupplieris a streamingBytesSuppliersuitable for reactive asynchronous usage.
-
-
Constructor Summary
Constructors Constructor Description PublisherBytesSupplier()Constructs aPublisherBytesSupplier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendContent(byte[] data, boolean lastChunk)Appends content to theBytesSupplier.byte[]getAsBytes()Returns thebyte[]presentation of the object.voidsubscribe(java.util.function.Consumer<byte[]> subscriber)Adds the subscriber to theBytesSupplierto get notified about additional data.java.nio.ByteBuffertoByteBuffer()Returns theByteBufferpresentation of the object.voidwaitToRead()Waits until completed before passing thread (BLOCKS THREAD!).-
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
-
-
-
-
Constructor Detail
-
PublisherBytesSupplier
public PublisherBytesSupplier()
Constructs aPublisherBytesSupplier.
-
-
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
-
subscribe
public void subscribe(java.util.function.Consumer<byte[]> subscriber)
Adds the subscriber to theBytesSupplierto get notified about additional data.- Parameters:
subscriber- a consumer function that will receive bytes when new daata is added and null when completed
-
waitToRead
public void waitToRead()
Waits until completed before passing thread (BLOCKS THREAD!).
-
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
-
-