public class ByteBufInputStream extends InputStream implements DataInput
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.
ByteBufOutputStream
Constructor and Description |
---|
ByteBufInputStream(ByteBuf buffer)
Creates a new stream which reads data from the specified
buffer
starting at the current readerIndex and ending at the current
writerIndex . |
ByteBufInputStream(ByteBuf buffer,
boolean releaseOnClose)
Creates a new stream which reads data from the specified
buffer
starting at the current readerIndex and ending at the current
writerIndex . |
ByteBufInputStream(ByteBuf buffer,
int length)
Creates a new stream which reads data from the specified
buffer
starting at the current readerIndex and ending at
readerIndex + length . |
ByteBufInputStream(ByteBuf buffer,
int length,
boolean releaseOnClose)
Creates a new stream which reads data from the specified
buffer
starting at the current readerIndex and ending at
readerIndex + length . |
Modifier and Type | Method and 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) |
read
public ByteBufInputStream(ByteBuf buffer)
buffer
starting at the current readerIndex
and ending at the current
writerIndex
.buffer
- The buffer which provides the content for this InputStream
.public ByteBufInputStream(ByteBuf buffer, int length)
buffer
starting at the current readerIndex
and ending at
readerIndex + length
.buffer
- The buffer which provides the content for this InputStream
.length
- The length of the buffer to use for this InputStream
.IndexOutOfBoundsException
- if readerIndex + length
is greater than
writerIndex
public ByteBufInputStream(ByteBuf buffer, boolean releaseOnClose)
buffer
starting at the current readerIndex
and ending at the current
writerIndex
.buffer
- The buffer which provides the content for this InputStream
.releaseOnClose
- true
means that when close()
is called then ReferenceCounted.release()
will
be called on buffer
.public ByteBufInputStream(ByteBuf buffer, int length, boolean releaseOnClose)
buffer
starting at the current readerIndex
and ending at
readerIndex + length
.buffer
- The buffer which provides the content for this InputStream
.length
- The length of the buffer to use for this InputStream
.releaseOnClose
- true
means that when close()
is called then ReferenceCounted.release()
will
be called on buffer
.IndexOutOfBoundsException
- if readerIndex + length
is greater than
writerIndex
public int readBytes()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class InputStream
IOException
public int available() throws IOException
available
in class InputStream
IOException
public void mark(int readlimit)
mark
in class InputStream
public boolean markSupported()
markSupported
in class InputStream
public int read() throws IOException
read
in class InputStream
IOException
public int read(byte[] b, int off, int len) throws IOException
read
in class InputStream
IOException
public void reset() throws IOException
reset
in class InputStream
IOException
public long skip(long n) throws IOException
skip
in class InputStream
IOException
public boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
public byte readByte() throws IOException
readByte
in interface DataInput
IOException
public char readChar() throws IOException
readChar
in interface DataInput
IOException
public double readDouble() throws IOException
readDouble
in interface DataInput
IOException
public float readFloat() throws IOException
readFloat
in interface DataInput
IOException
public void readFully(byte[] b) throws IOException
readFully
in interface DataInput
IOException
public void readFully(byte[] b, int off, int len) throws IOException
readFully
in interface DataInput
IOException
public int readInt() throws IOException
readInt
in interface DataInput
IOException
public String readLine() throws IOException
readLine
in interface DataInput
IOException
public long readLong() throws IOException
readLong
in interface DataInput
IOException
public short readShort() throws IOException
readShort
in interface DataInput
IOException
public String readUTF() throws IOException
readUTF
in interface DataInput
IOException
public int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
public int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
public int skipBytes(int n) throws IOException
skipBytes
in interface DataInput
IOException
Copyright © 2008–2017 The Netty Project. All rights reserved.