Class NettyReadableBuffer
java.lang.Object
io.grpc.internal.AbstractReadableBuffer
io.grpc.netty.NettyReadableBuffer
- All Implemented Interfaces:
ReadableBuffer, Closeable, AutoCloseable
A
Buffer implementation that is backed by a Netty ByteBuf. This class
does not call ByteBuf.retain(int), so if that is needed it should be called prior to creating
this buffer.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]array()Gets the backing array for this buffer.intGets the offset in the backing array of the current read position.(package private) io.netty.buffer.ByteBufbuffer()booleanIndicates whether or notReadableBuffer.getByteBuffer()operation is supported for this buffer.voidclose()If the first call to close, callsReferenceCounted.release()to release the internal Netty buffer.Gets aByteBufferthat contains some bytes of the content next to be read, ornullif this buffer has been exhausted.booleanhasArray()Indicates whether or not this buffer exposes a backing array.voidmark()Marks the current position in this buffer.booleanIndicates whether or notReadableBuffer.mark()operation is supported for this buffer.intGets the current number of readable bytes remaining in this buffer.voidreadBytes(byte[] dest, int index, int length) Readslengthbytes from this buffer and writes them to the destination array.readBytes(int length) Readslengthbytes from this buffer and returns a new Buffer containing them.voidreadBytes(OutputStream dest, int length) Readslengthbytes from this buffer and writes them to the destination stream.voidreadBytes(ByteBuffer dest) Reads from this buffer until the destination's position reaches its limit, and increases the read position by the number of the transferred bytes.intReads the next unsigned byte from this buffer and increments the read position by 1.voidreset()Repositions this buffer to the position at the timeReadableBuffer.mark()was last called on this buffer.voidskipBytes(int length) Increments the read position by the given length.voidtouch()Note that the current callsite has access to this buffer, or do nothing.Methods inherited from class AbstractReadableBuffer
checkReadable, readInt
-
Field Details
-
buffer
private final io.netty.buffer.ByteBuf buffer -
closed
private boolean closed
-
-
Constructor Details
-
NettyReadableBuffer
NettyReadableBuffer(io.netty.buffer.ByteBuf buffer)
-
-
Method Details
-
buffer
io.netty.buffer.ByteBuf buffer() -
readableBytes
public int readableBytes()Description copied from interface:ReadableBufferGets the current number of readable bytes remaining in this buffer. -
skipBytes
public void skipBytes(int length) Description copied from interface:ReadableBufferIncrements the read position by the given length. -
readUnsignedByte
public int readUnsignedByte()Description copied from interface:ReadableBufferReads the next unsigned byte from this buffer and increments the read position by 1. -
readBytes
public void readBytes(byte[] dest, int index, int length) Description copied from interface:ReadableBufferReadslengthbytes from this buffer and writes them to the destination array. Increments the read position bylength.- Parameters:
dest- the destination array to receive the bytes.index- the starting offset in the destination array.length- the number of bytes to be copied.
-
readBytes
Description copied from interface:ReadableBufferReads from this buffer until the destination's position reaches its limit, and increases the read position by the number of the transferred bytes.- Parameters:
dest- the destination buffer to receive the bytes.
-
readBytes
Description copied from interface:ReadableBufferReadslengthbytes from this buffer and writes them to the destination stream. Increments the read position bylength. If the required bytes are not readable, throwsIndexOutOfBoundsException.- Parameters:
dest- the destination stream to receive the bytes.length- the number of bytes to be copied.
-
readBytes
Description copied from interface:ReadableBufferReadslengthbytes from this buffer and returns a new Buffer containing them. Some implementations may return a Buffer sharing the backing memory with this buffer to prevent copying. However, that means that the returned buffer may keep the (possibly much larger) backing memory in use even after this buffer is closed.- Parameters:
length- the number of bytes to contain in returned Buffer.
-
hasArray
public boolean hasArray()Description copied from interface:ReadableBufferIndicates whether or not this buffer exposes a backing array.- Specified by:
hasArrayin interfaceReadableBuffer- Overrides:
hasArrayin classAbstractReadableBuffer
-
array
public byte[] array()Description copied from interface:ReadableBufferGets the backing array for this buffer. This is an optional method, so callers should first checkReadableBuffer.hasArray().- Specified by:
arrayin interfaceReadableBuffer- Overrides:
arrayin classAbstractReadableBuffer
-
arrayOffset
public int arrayOffset()Description copied from interface:ReadableBufferGets the offset in the backing array of the current read position. This is an optional method, so callers should first checkReadableBuffer.hasArray()- Specified by:
arrayOffsetin interfaceReadableBuffer- Overrides:
arrayOffsetin classAbstractReadableBuffer
-
touch
public void touch()Description copied from interface:ReadableBufferNote that the current callsite has access to this buffer, or do nothing. This is only useful when the buffer has leak detection and intrumentation to record usages before the buffer was leaked. That can make it much easier to track down where the buffer was leaked. If this isn't such a buffer, the method does nothing. -
markSupported
public boolean markSupported()Description copied from interface:ReadableBufferIndicates whether or notReadableBuffer.mark()operation is supported for this buffer.- Specified by:
markSupportedin interfaceReadableBuffer- Overrides:
markSupportedin classAbstractReadableBuffer
-
mark
public void mark()Description copied from interface:ReadableBufferMarks the current position in this buffer. A subsequent call to theReadableBuffer.reset()method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.- Specified by:
markin interfaceReadableBuffer- Overrides:
markin classAbstractReadableBuffer
-
reset
public void reset()Description copied from interface:ReadableBufferRepositions this buffer to the position at the timeReadableBuffer.mark()was last called on this buffer.- Specified by:
resetin interfaceReadableBuffer- Overrides:
resetin classAbstractReadableBuffer
-
byteBufferSupported
public boolean byteBufferSupported()Description copied from interface:ReadableBufferIndicates whether or notReadableBuffer.getByteBuffer()operation is supported for this buffer.- Specified by:
byteBufferSupportedin interfaceReadableBuffer- Overrides:
byteBufferSupportedin classAbstractReadableBuffer
-
getByteBuffer
Description copied from interface:ReadableBufferGets aByteBufferthat contains some bytes of the content next to be read, ornullif this buffer has been exhausted. The number of bytes contained in the returned buffer is implementation specific. The position of this buffer is unchanged after calling this method. The returned buffer's content should not be modified, but the position, limit, and mark may be changed. Operations for changing the position, limit, and mark of the returned buffer does not affect the position, limit, and mark of this buffer. Buffers returned by this method have independent position, limit and mark. This is an optional method, so callers should first checkReadableBuffer.byteBufferSupported().- Specified by:
getByteBufferin interfaceReadableBuffer- Overrides:
getByteBufferin classAbstractReadableBuffer
-
close
public void close()If the first call to close, callsReferenceCounted.release()to release the internal Netty buffer.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceReadableBuffer- Overrides:
closein classAbstractReadableBuffer
-