Package io.camunda.client.impl.http
Class CircularBufferInputStream
java.lang.Object
java.io.InputStream
io.camunda.client.impl.http.CircularBufferInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A custom input stream that stores data in a circular buffer with a fixed capacity. This
implementation offers a non-blocking asynchronous API for writing the data into the buffer.
The writing thread can check the available space in the buffer by calling getAvailableSpace(). If the buffer is full, the writing thread must avoid writing more data. A
callback can be set by the writing thread to be notified when space is available in the buffer.
See CircularBufferInputStream.CapacityCallback.
The buffer space is freed up as the reading thread reads the data from the buffer. The reading
thread consumes data using the standard InputStream API, blocking if no data is
available.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidintintread()intread(byte[] b, int off, int len) voidsetCapacityCallback(CircularBufferInputStream.CapacityCallback capacityCallback) voidvoidwrite(ByteBuffer data) Writes the data into the buffer.Methods inherited from class java.io.InputStream
available, close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
CircularBufferInputStream
public CircularBufferInputStream(int capacity)
-
-
Method Details
-
setCapacityCallback
-
write
Writes the data into the buffer. This method does not block the calling thread if the buffer is full, instead it throws anIOException. This means that the writing thread must handle capacity issues by proactively checking the available space in the buffer before writing data.- Throws:
IOException- if the buffer is full
-
endOfStream
public void endOfStream() -
signalError
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
getAvailableSpace
public int getAvailableSpace()
-