Package io.netty5.buffer
Class ByteBufInputStream
- java.lang.Object
-
- java.io.InputStream
-
- io.netty5.buffer.ByteBufInputStream
-
- All Implemented Interfaces:
Closeable
,DataInput
,AutoCloseable
public class ByteBufInputStream extends InputStream implements DataInput
AnInputStream
which reads data from aByteBuf
.A read operation against this stream will occur at the
readerIndex
of its underlying buffer and thereaderIndex
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, updatingByteBuf.writerIndex()
will not affect the return value ofavailable()
.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:
ByteBufOutputStream
-
-
Constructor Summary
Constructors Constructor Description ByteBufInputStream(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
mark(int readlimit)
boolean
markSupported()
int
read()
int
read(byte[] b, int off, int len)
boolean
readBoolean()
byte
readByte()
int
readBytes()
Returns the number of read bytes by this stream so far.char
readChar()
double
readDouble()
float
readFloat()
void
readFully(byte[] b)
void
readFully(byte[] b, int off, int len)
int
readInt()
String
readLine()
long
readLong()
short
readShort()
int
readUnsignedByte()
int
readUnsignedShort()
String
readUTF()
void
reset()
long
skip(long n)
int
skipBytes(int n)
-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, transferTo
-
-
-
-
Constructor Detail
-
ByteBufInputStream
public ByteBufInputStream(ByteBuf buffer)
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
public ByteBufInputStream(ByteBuf buffer, int length)
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
public ByteBufInputStream(ByteBuf buffer, boolean releaseOnClose)
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
public 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
.- 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 Detail
-
readBytes
public int readBytes()
Returns the number of read bytes by this stream so far.
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- 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
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
reset
public void reset() throws IOException
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
skip
public long skip(long n) throws IOException
- Overrides:
skip
in classInputStream
- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException
- Specified by:
readBoolean
in interfaceDataInput
- Throws:
IOException
-
readByte
public byte readByte() throws IOException
- Specified by:
readByte
in interfaceDataInput
- Throws:
IOException
-
readChar
public char readChar() throws IOException
- Specified by:
readChar
in interfaceDataInput
- Throws:
IOException
-
readDouble
public double readDouble() throws IOException
- Specified by:
readDouble
in interfaceDataInput
- Throws:
IOException
-
readFloat
public float readFloat() throws IOException
- Specified by:
readFloat
in interfaceDataInput
- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException
- Specified by:
readFully
in interfaceDataInput
- Throws:
IOException
-
readInt
public int readInt() throws IOException
- Specified by:
readInt
in interfaceDataInput
- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLine
in interfaceDataInput
- Throws:
IOException
-
readLong
public long readLong() throws IOException
- Specified by:
readLong
in interfaceDataInput
- Throws:
IOException
-
readShort
public short readShort() throws IOException
- Specified by:
readShort
in interfaceDataInput
- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTF
in interfaceDataInput
- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException
- Specified by:
readUnsignedByte
in interfaceDataInput
- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException
- Specified by:
readUnsignedShort
in interfaceDataInput
- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException
- Specified by:
skipBytes
in interfaceDataInput
- Throws:
IOException
-
-