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:
-
Constructor Summary
ConstructorsConstructorDescriptionByteBufInputStream(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
Modifier and TypeMethodDescriptionintvoidclose()voidmark(int readlimit) booleanintread()intread(byte[] b, int off, int len) booleanbytereadByte()intReturns the number of read bytes by this stream so far.charreadChar()doublefloatvoidreadFully(byte[] b) voidreadFully(byte[] b, int off, int len) intreadInt()readLine()longreadLong()shortintintreadUTF()voidreset()longskip(long n) intskipBytes(int n) Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
ByteBufInputStream
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
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
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
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 Details
-
readBytes
public int readBytes()Returns the number of read bytes by this stream so far. -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
available
- Overrides:
availablein classInputStream- Throws:
IOException
-
mark
public void mark(int readlimit) - Overrides:
markin classInputStream
-
markSupported
public boolean markSupported()- Overrides:
markSupportedin classInputStream
-
read
- Specified by:
readin classInputStream- Throws:
IOException
-
read
- Overrides:
readin classInputStream- Throws:
IOException
-
reset
- Overrides:
resetin classInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classInputStream- Throws:
IOException
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
IOException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
IOException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
IOException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
IOException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
IOException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
IOException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
IOException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
IOException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
IOException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
IOException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
IOException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
IOException
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
IOException
-