Package io.apicurio.registry.serde.utils
Class ByteBufferInputStream
java.lang.Object
java.io.InputStream
io.apicurio.registry.serde.utils.ByteBufferInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionByteBufferInputStream(ByteBuffer buffer) Creates a new ByteBufferInputStream that reads from the given buffer. -
Method Summary
Modifier and TypeMethodDescriptionintReturns an estimate of the number of bytes that can be read from this input stream.intread()Reads the next byte of data from the input stream.intread(byte[] bytes, int off, int len) Reads up to len bytes of data from the input stream into an array of bytes.longskip(long n) Skips over and discards n bytes of data from this input stream.Methods inherited from class java.io.InputStream
close, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skipNBytes, transferTo
-
Constructor Details
-
ByteBufferInputStream
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:
readin classInputStream- 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:
readin classInputStream- Parameters:
bytes- the buffer into which the data is readoff- the start offset in array bytes at which the data is writtenlen- 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
Returns an estimate of the number of bytes that can be read from this input stream.- Overrides:
availablein classInputStream- 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:
skipin classInputStream- Parameters:
n- the number of bytes to be skipped- Returns:
- the actual number of bytes skipped
-