Package io.netty.buffer
Class ByteBufInputStream
java.lang.Object
java.io.InputStream
io.netty.buffer.ByteBufInputStream
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
An
InputStream
which reads data from a ByteBuf
.
A read operation against this stream will occur at the readerIndex
of its underlying buffer and the readerIndex
will increase during
the read operation. Please note that it only reads up to the number of
readable bytes determined at the moment of construction. Therefore,
updating ByteBuf.writerIndex()
will not affect the return
value of available()
.
This stream implements DataInput
for your convenience.
The endianness of the stream is not always big endian but depends on
the endianness of the underlying buffer.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteBuf
private boolean
private final int
private StringBuilder
private final boolean
To preserve backwards compatibility (which didn't transfer ownership) we support a conditional flag which indicates ifbuffer
should be released when thisInputStream
is closed.private final int
-
Constructor Summary
ConstructorsConstructorDescriptionByteBufInputStream
(ByteBuf buffer) Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending at the currentwriterIndex
.ByteBufInputStream
(ByteBuf buffer, boolean releaseOnClose) Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending at the currentwriterIndex
.ByteBufInputStream
(ByteBuf buffer, int length) Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending atreaderIndex + length
.ByteBufInputStream
(ByteBuf buffer, int length, boolean releaseOnClose) Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending atreaderIndex + length
. -
Method Summary
Modifier and TypeMethodDescriptionint
private void
checkAvailable
(int fieldSize) void
close()
void
mark
(int readlimit) boolean
int
read()
int
read
(byte[] b, int off, int len) boolean
byte
readByte()
int
Returns the number of read bytes by this stream so far.char
readChar()
double
float
void
readFully
(byte[] b) void
readFully
(byte[] b, int off, int len) int
readInt()
readLine()
long
readLong()
short
int
int
readUTF()
void
reset()
long
skip
(long n) int
skipBytes
(int n) Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
buffer
-
startIndex
private final int startIndex -
endIndex
private final int endIndex -
closed
private boolean closed -
releaseOnClose
private final boolean releaseOnCloseTo preserve backwards compatibility (which didn't transfer ownership) we support a conditional flag which indicates ifbuffer
should be released when thisInputStream
is closed. However in future releases ownership should always be transferred and callers of this class should callReferenceCounted.retain()
if necessary. -
lineBuf
-
-
Constructor Details
-
ByteBufInputStream
Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending at the currentwriterIndex
.- Parameters:
buffer
- The buffer which provides the content for thisInputStream
.
-
ByteBufInputStream
Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending atreaderIndex + length
.- Parameters:
buffer
- The buffer which provides the content for thisInputStream
.length
- The length of the buffer to use for thisInputStream
.- Throws:
IndexOutOfBoundsException
- ifreaderIndex + length
is greater thanwriterIndex
-
ByteBufInputStream
Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending at the currentwriterIndex
.- Parameters:
buffer
- The buffer which provides the content for thisInputStream
.releaseOnClose
-true
means that whenclose()
is called thenReferenceCounted.release()
will be called onbuffer
.
-
ByteBufInputStream
Creates a new stream which reads data from the specifiedbuffer
starting at the currentreaderIndex
and ending atreaderIndex + length
.- Parameters:
buffer
- The buffer which provides the content for thisInputStream
.length
- The length of the buffer to use for thisInputStream
.releaseOnClose
-true
means that whenclose()
is called thenReferenceCounted.release()
will be called onbuffer
.- Throws:
IndexOutOfBoundsException
- ifreaderIndex + length
is greater thanwriterIndex
-
-
Method Details
-
readBytes
public int readBytes()Returns the number of read bytes by this stream so far. -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classInputStream
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
readBoolean
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readChar
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readDouble
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readFloat
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readInt
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLine
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readLong
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readShort
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUTF
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
skipBytes
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
checkAvailable
- Throws:
IOException
-