Package io.pravega.common.util
Interface BufferView.Reader
-
- All Known Implementing Classes:
AbstractBufferView.AbstractReader
- Enclosing interface:
- BufferView
public static interface BufferView.ReaderDefines a reader for aBufferView.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classBufferView.Reader.OutOfBoundsExceptionException that is thrown whenever an attempt is made to read beyond the bounds of aBufferView.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description intavailable()Gets a value indicating the number of bytes available to read.bytereadByte()Reads one byte and advances the reader position by 1.intreadBytes(java.nio.ByteBuffer byteBuffer)Reads a number of bytes into the givenByteBufferusing the most efficient method for the implementation of thisBufferView.ArrayViewreadFully(int bufferSize)Copies all the remaining bytes from thisBufferView.Readerinto a newArrayView.intreadInt()Reads 4 bytes (and advances the reader position by 4) and composes a 32-bit Integer (Big-Endian).longreadLong()Reads 8 bytes (and advances the reader position by 4) and composes a 64-bit Long (Big-Endian).BufferViewreadSlice(int length)Returns aBufferViewthat is a representation of the next bytes starting at the given position.
-
-
-
Method Detail
-
available
int available()
Gets a value indicating the number of bytes available to read.- Returns:
- The number of bytes available to read.
-
readBytes
int readBytes(java.nio.ByteBuffer byteBuffer)
Reads a number of bytes into the givenByteBufferusing the most efficient method for the implementation of thisBufferView.- Parameters:
byteBuffer- The targetByteBuffer.- Returns:
- The number of bytes copied. This should be
. If this returns 0, then either the givenMath.min(available(), byteBuffer.remaining())ByteBufferhasBuffer.remaining()equal to 0, or there are no more bytes to be read (available()is 0).
-
readByte
byte readByte()
Reads one byte and advances the reader position by 1.- Returns:
- The read byte.
- Throws:
BufferView.Reader.OutOfBoundsException- Ifavailable()is 0.
-
readInt
int readInt()
Reads 4 bytes (and advances the reader position by 4) and composes a 32-bit Integer (Big-Endian).- Returns:
- The read int.
- Throws:
BufferView.Reader.OutOfBoundsException- Ifavailable()is less thanInteger.BYTES.
-
readLong
long readLong()
Reads 8 bytes (and advances the reader position by 4) and composes a 64-bit Long (Big-Endian).- Returns:
- The read long.
- Throws:
BufferView.Reader.OutOfBoundsException- Ifavailable()is less thanLong.BYTES.
-
readSlice
BufferView readSlice(int length)
Returns aBufferViewthat is a representation of the next bytes starting at the given position. The reader position will be advanced by the requested number of bytes.- Parameters:
length- The number of bytes to slice out.- Returns:
- A
BufferViewthat represents the given bytes. ThisBufferViewrepresents a view into the underlyingBufferViewand is not a copy of the given range. - Throws:
BufferView.Reader.OutOfBoundsException- Ifavailable()is less than length.
-
readFully
ArrayView readFully(int bufferSize)
Copies all the remaining bytes from thisBufferView.Readerinto a newArrayView. The reader position will be set to the end of theBufferView.- Parameters:
bufferSize- The maximum number of bytes to copy at each iteration. Set toInteger.MAX_VALUEto attempt to copy the whole buffer at once.- Returns:
- A new
ByteArraySegmentwith the remaining contents ofBufferView.Reader.
-
-