Package io.grpc.internal
Class ReadableBuffers.ByteArrayWrapper
java.lang.Object
io.grpc.internal.AbstractReadableBuffer
io.grpc.internal.ReadableBuffers.ByteArrayWrapper
- All Implemented Interfaces:
ReadableBuffer
,Closeable
,AutoCloseable
- Enclosing class:
ReadableBuffers
A
ReadableBuffer
that is backed by a byte array.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionByteArrayWrapper
(byte[] bytes) ByteArrayWrapper
(byte[] bytes, int offset, int length) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
array()
Gets the backing array for this buffer.int
Gets the offset in the backing array of the current read position.boolean
hasArray()
Indicates whether or not this buffer exposes a backing array.void
mark()
Marks the current position in this buffer.boolean
Indicates whether or notReadableBuffer.mark()
operation is supported for this buffer.int
Gets the current number of readable bytes remaining in this buffer.void
readBytes
(byte[] dest, int destIndex, int length) Readslength
bytes from this buffer and writes them to the destination array.readBytes
(int length) Readslength
bytes from this buffer and returns a new Buffer containing them.void
readBytes
(OutputStream dest, int length) Readslength
bytes from this buffer and writes them to the destination stream.void
readBytes
(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.int
Reads the next unsigned byte from this buffer and increments the read position by 1.void
reset()
Repositions this buffer to the position at the timeReadableBuffer.mark()
was last called on this buffer.void
skipBytes
(int length) Increments the read position by the given length.Methods inherited from class io.grpc.internal.AbstractReadableBuffer
byteBufferSupported, checkReadable, close, getByteBuffer, readInt
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.grpc.internal.ReadableBuffer
touch
-
Field Details
-
offset
int offset -
end
final int end -
bytes
final byte[] bytes -
mark
int mark
-
-
Constructor Details
-
ByteArrayWrapper
ByteArrayWrapper(byte[] bytes) -
ByteArrayWrapper
ByteArrayWrapper(byte[] bytes, int offset, int length)
-
-
Method Details
-
readableBytes
public int readableBytes()Description copied from interface:ReadableBuffer
Gets the current number of readable bytes remaining in this buffer. -
skipBytes
public void skipBytes(int length) Description copied from interface:ReadableBuffer
Increments the read position by the given length. -
readUnsignedByte
public int readUnsignedByte()Description copied from interface:ReadableBuffer
Reads the next unsigned byte from this buffer and increments the read position by 1. -
readBytes
public void readBytes(byte[] dest, int destIndex, int length) Description copied from interface:ReadableBuffer
Readslength
bytes from this buffer and writes them to the destination array. Increments the read position bylength
.- Parameters:
dest
- the destination array to receive the bytes.destIndex
- the starting offset in the destination array.length
- the number of bytes to be copied.
-
readBytes
Description copied from interface:ReadableBuffer
Reads 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:ReadableBuffer
Readslength
bytes 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.- Throws:
IOException
- thrown if any error was encountered while writing to the stream.
-
readBytes
Description copied from interface:ReadableBuffer
Readslength
bytes 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:ReadableBuffer
Indicates whether or not this buffer exposes a backing array.- Specified by:
hasArray
in interfaceReadableBuffer
- Overrides:
hasArray
in classAbstractReadableBuffer
-
array
public byte[] array()Description copied from interface:ReadableBuffer
Gets the backing array for this buffer. This is an optional method, so callers should first checkReadableBuffer.hasArray()
.- Specified by:
array
in interfaceReadableBuffer
- Overrides:
array
in classAbstractReadableBuffer
-
arrayOffset
public int arrayOffset()Description copied from interface:ReadableBuffer
Gets the offset in the backing array of the current read position. This is an optional method, so callers should first checkReadableBuffer.hasArray()
- Specified by:
arrayOffset
in interfaceReadableBuffer
- Overrides:
arrayOffset
in classAbstractReadableBuffer
-
markSupported
public boolean markSupported()Description copied from interface:ReadableBuffer
Indicates whether or notReadableBuffer.mark()
operation is supported for this buffer.- Specified by:
markSupported
in interfaceReadableBuffer
- Overrides:
markSupported
in classAbstractReadableBuffer
-
mark
public void mark()Description copied from interface:ReadableBuffer
Marks 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:
mark
in interfaceReadableBuffer
- Overrides:
mark
in classAbstractReadableBuffer
-
reset
public void reset()Description copied from interface:ReadableBuffer
Repositions this buffer to the position at the timeReadableBuffer.mark()
was last called on this buffer.- Specified by:
reset
in interfaceReadableBuffer
- Overrides:
reset
in classAbstractReadableBuffer
-