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
AnInputStreamwhich reads data from aByteBuf.A read operation against this stream will occur at the
readerIndexof its underlying buffer and thereaderIndexwill 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
DataInputfor 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 specifiedbufferstarting at the currentreaderIndexand ending at the currentwriterIndex.ByteBufInputStream(ByteBuf buffer, boolean releaseOnClose)Creates a new stream which reads data from the specifiedbufferstarting at the currentreaderIndexand ending at the currentwriterIndex.ByteBufInputStream(ByteBuf buffer, int length)Creates a new stream which reads data from the specifiedbufferstarting at the currentreaderIndexand ending atreaderIndex + length.ByteBufInputStream(ByteBuf buffer, int length, boolean releaseOnClose)Creates a new stream which reads data from the specifiedbufferstarting at the currentreaderIndexand ending atreaderIndex + length.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()voidmark(int readlimit)booleanmarkSupported()intread()intread(byte[] b, int off, int len)booleanreadBoolean()bytereadByte()intreadBytes()Returns the number of read bytes by this stream so far.charreadChar()doublereadDouble()floatreadFloat()voidreadFully(byte[] b)voidreadFully(byte[] b, int off, int len)intreadInt()StringreadLine()longreadLong()shortreadShort()intreadUnsignedByte()intreadUnsignedShort()StringreadUTF()voidreset()longskip(long n)intskipBytes(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 specifiedbufferstarting at the currentreaderIndexand 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 specifiedbufferstarting at the currentreaderIndexand 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 + lengthis greater thanwriterIndex
-
ByteBufInputStream
public ByteBufInputStream(ByteBuf buffer, boolean releaseOnClose)
Creates a new stream which reads data from the specifiedbufferstarting at the currentreaderIndexand ending at the currentwriterIndex.- Parameters:
buffer- The buffer which provides the content for thisInputStream.releaseOnClose-truemeans 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 specifiedbufferstarting at the currentreaderIndexand ending atreaderIndex + length.- Parameters:
buffer- The buffer which provides the content for thisInputStream.length- The length of the buffer to use for thisInputStream.releaseOnClose-truemeans that whenclose()is called thenReferenceCounted.release()will be called onbuffer.- Throws:
IndexOutOfBoundsException- ifreaderIndex + lengthis 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit)
- Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classInputStream
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException- Overrides:
readin classInputStream- Throws:
IOException
-
reset
public void reset() throws IOException- Overrides:
resetin classInputStream- Throws:
IOException
-
skip
public long skip(long n) throws IOException- Overrides:
skipin classInputStream- Throws:
IOException
-
readBoolean
public boolean readBoolean() throws IOException- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
public byte readByte() throws IOException- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readChar
public char readChar() throws IOException- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readDouble
public double readDouble() throws IOException- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readFloat
public float readFloat() throws IOException- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] b) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
public void readFully(byte[] b, int off, int len) throws IOException- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readInt
public int readInt() throws IOException- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLine
public String readLine() throws IOException
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readLong
public long readLong() throws IOException- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readShort
public short readShort() throws IOException- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUTF
public String readUTF() throws IOException
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
readUnsignedByte
public int readUnsignedByte() throws IOException- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readUnsignedShort
public int readUnsignedShort() throws IOException- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
skipBytes
public int skipBytes(int n) throws IOException- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-
-