Class ByteBufferInputStream

java.lang.Object
java.io.InputStream
io.apicurio.registry.serde.utils.ByteBufferInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public final class ByteBufferInputStream extends InputStream
A byte buffer backed input stream that allows reading from a ByteBuffer without copying data. This implementation wraps a ByteBuffer and provides InputStream operations directly on the buffer, avoiding the memory overhead of copying buffer contents to a byte array.
  • Constructor Details

    • ByteBufferInputStream

      public ByteBufferInputStream(ByteBuffer buffer)
      Creates a new ByteBufferInputStream that reads from the given buffer. The stream will read from the buffer's current position to its limit.
      Parameters:
      buffer - the ByteBuffer to read from
  • Method Details

    • read

      public int read()
      Reads the next byte of data from the input stream.
      Specified by:
      read in class InputStream
      Returns:
      the next byte of data, or -1 if the end of the stream is reached
    • read

      public int read(byte[] bytes, int off, int len)
      Reads up to len bytes of data from the input stream into an array of bytes.
      Overrides:
      read in class InputStream
      Parameters:
      bytes - the buffer into which the data is read
      off - the start offset in array bytes at which the data is written
      len - the maximum number of bytes to read
      Returns:
      the total number of bytes read into the buffer, or -1 if there is no more data
    • available

      public int available() throws IOException
      Returns an estimate of the number of bytes that can be read from this input stream.
      Overrides:
      available in class InputStream
      Returns:
      the number of bytes remaining in the buffer
      Throws:
      IOException - if an I/O error occurs
    • skip

      public long skip(long n)
      Skips over and discards n bytes of data from this input stream. This implementation is O(1) as it simply advances the buffer position.
      Overrides:
      skip in class InputStream
      Parameters:
      n - the number of bytes to be skipped
      Returns:
      the actual number of bytes skipped