Class CircularBufferInputStream

java.lang.Object
java.io.InputStream
io.camunda.client.impl.http.CircularBufferInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class CircularBufferInputStream extends InputStream
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.

  • Constructor Details

    • CircularBufferInputStream

      public CircularBufferInputStream(int capacity)
  • Method Details

    • setCapacityCallback

      public void setCapacityCallback(CircularBufferInputStream.CapacityCallback capacityCallback)
    • write

      public void write(ByteBuffer data) throws IOException
      Writes the data into the buffer. This method does not block the calling thread if the buffer is full, instead it throws an IOException. 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

      public void signalError(IOException e)
    • read

      public int read() throws IOException
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(@Nonnull byte[] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • getAvailableSpace

      public int getAvailableSpace()