public class DefaultDataBuffer extends Object implements DataBuffer
DataBuffer interface that uses a
ByteBuffer internally. with separate read and write positions.
Constructed using the DefaultDataBufferFactory.
Inspired by Netty's ByteBuf. Introduced so that non-Netty runtimes
(i.e. Servlet) do not require Netty on the classpath.
DefaultDataBufferFactory| 限定符和类型 | 方法和说明 |
|---|---|
ByteBuffer |
asByteBuffer()
Expose this buffer's bytes as a
ByteBuffer. |
ByteBuffer |
asByteBuffer(int index,
int length)
Expose a subsequence of this buffer's bytes as a
ByteBuffer. |
InputStream |
asInputStream()
Expose this buffer's data as an
InputStream. |
InputStream |
asInputStream(boolean releaseOnClose)
Expose this buffer's data as an
InputStream. |
OutputStream |
asOutputStream()
Expose this buffer's data as an
OutputStream. |
int |
capacity()
Return the number of bytes that this buffer can contain.
|
DefaultDataBuffer |
capacity(int newCapacity)
Set the number of bytes that this buffer can contain.
|
boolean |
equals(Object other) |
DefaultDataBufferFactory |
factory()
Return the
DataBufferFactory that created this buffer. |
byte |
getByte(int index)
Read a single byte at the given index from this data buffer.
|
ByteBuffer |
getNativeBuffer()
Directly exposes the native
ByteBuffer that this buffer is based on. |
int |
hashCode() |
int |
indexOf(IntPredicate predicate,
int fromIndex)
Return the index of the first byte in this buffer that matches
the given predicate.
|
int |
lastIndexOf(IntPredicate predicate,
int fromIndex)
Return the index of the last byte in this buffer that matches
the given predicate.
|
byte |
read()
Read a single byte from the current reading position from this data buffer.
|
DefaultDataBuffer |
read(byte[] destination)
Read this buffer's data into the specified destination, starting at the current
reading position of this buffer.
|
DefaultDataBuffer |
read(byte[] destination,
int offset,
int length)
Read at most
length bytes of this buffer into the specified destination,
starting at the current reading position of this buffer. |
int |
readableByteCount()
Return the number of bytes that can be read from this data buffer.
|
int |
readPosition()
Return the position from which this buffer will read.
|
DefaultDataBuffer |
readPosition(int readPosition)
Set the position from which this buffer will read.
|
DefaultDataBuffer |
slice(int index,
int length)
Create a new
DataBuffer whose contents is a shared subsequence of this
data buffer's content. |
String |
toString() |
int |
writableByteCount()
Return the number of bytes that can be written to this data buffer.
|
DefaultDataBuffer |
write(byte b)
Write a single byte into this buffer at the current writing position.
|
DefaultDataBuffer |
write(byte[] source)
Write the given source into this buffer, startin at the current writing position
of this buffer.
|
DefaultDataBuffer |
write(byte[] source,
int offset,
int length)
Write at most
length bytes of the given source into this buffer, starting
at the current writing position of this buffer. |
DefaultDataBuffer |
write(ByteBuffer... byteBuffers)
Write one or more
ByteBuffer to this buffer, starting at the current
writing position. |
DefaultDataBuffer |
write(DataBuffer... buffers)
Write one or more
DataBuffers to this buffer, starting at the current
writing position. |
int |
writePosition()
Return the position to which this buffer will write.
|
DefaultDataBuffer |
writePosition(int writePosition)
Set the position to which this buffer will write.
|
public ByteBuffer getNativeBuffer()
ByteBuffer that this buffer is based on.public DefaultDataBufferFactory factory()
DataBufferDataBufferFactory that created this buffer.factory 在接口中 DataBufferpublic int indexOf(IntPredicate predicate, int fromIndex)
DataBufferindexOf 在接口中 DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate;
or -1 if none matchpublic int lastIndexOf(IntPredicate predicate, int fromIndex)
DataBufferlastIndexOf 在接口中 DataBufferpredicate - the predicate to matchfromIndex - the index to start the search frompredicate;
or -1 if none matchpublic int readableByteCount()
DataBufferreadableByteCount 在接口中 DataBufferpublic int writableByteCount()
DataBufferwritableByteCount 在接口中 DataBufferpublic int readPosition()
DataBufferreadPosition 在接口中 DataBufferpublic DefaultDataBuffer readPosition(int readPosition)
DataBufferreadPosition 在接口中 DataBufferreadPosition - the new read positionpublic int writePosition()
DataBufferwritePosition 在接口中 DataBufferpublic DefaultDataBuffer writePosition(int writePosition)
DataBufferwritePosition 在接口中 DataBufferwritePosition - the new write positionpublic int capacity()
DataBuffercapacity 在接口中 DataBufferpublic DefaultDataBuffer capacity(int newCapacity)
DataBufferIf the new capacity is lower than the current capacity, the contents of this buffer will be truncated. If the new capacity is higher than the current capacity, it will be expanded.
capacity 在接口中 DataBuffernewCapacity - the new capacitypublic byte getByte(int index)
DataBuffergetByte 在接口中 DataBufferindex - the index at which the byte will be readpublic byte read()
DataBufferread 在接口中 DataBufferpublic DefaultDataBuffer read(byte[] destination)
DataBufferread 在接口中 DataBufferdestination - the array into which the bytes are to be writtenpublic DefaultDataBuffer read(byte[] destination, int offset, int length)
DataBufferlength bytes of this buffer into the specified destination,
starting at the current reading position of this buffer.read 在接口中 DataBufferdestination - the array into which the bytes are to be writtenoffset - the index within destination of the first byte to be writtenlength - the maximum number of bytes to be written in destinationpublic DefaultDataBuffer write(byte b)
DataBufferwrite 在接口中 DataBufferb - the byte to be writtenpublic DefaultDataBuffer write(byte[] source)
DataBufferwrite 在接口中 DataBuffersource - the bytes to be written into this bufferpublic DefaultDataBuffer write(byte[] source, int offset, int length)
DataBufferlength bytes of the given source into this buffer, starting
at the current writing position of this buffer.write 在接口中 DataBuffersource - the bytes to be written into this bufferoffset - the index within source to start writing fromlength - the maximum number of bytes to be written from sourcepublic DefaultDataBuffer write(DataBuffer... buffers)
DataBufferDataBuffers to this buffer, starting at the current
writing position. It is the responsibility of the caller to
release the given data buffers.write 在接口中 DataBufferbuffers - the byte buffers to write into this bufferpublic DefaultDataBuffer write(ByteBuffer... byteBuffers)
DataBufferByteBuffer to this buffer, starting at the current
writing position.write 在接口中 DataBufferbyteBuffers - the byte buffers to write into this bufferpublic DefaultDataBuffer slice(int index, int length)
DataBufferDataBuffer whose contents is a shared subsequence of this
data buffer's content. Data between this data buffer and the returned buffer is
shared; though changes in the returned buffer's position will not be reflected
in the reading nor writing position of this data buffer.slice 在接口中 DataBufferindex - the index at which to start the slicelength - the length of the slicepublic ByteBuffer asByteBuffer()
DataBufferByteBuffer. Data between this
DataBuffer and the returned ByteBuffer is shared; though
changes in the returned buffer's position
will not be reflected in the reading nor writing position of this data buffer.asByteBuffer 在接口中 DataBufferpublic ByteBuffer asByteBuffer(int index, int length)
DataBufferByteBuffer. Data between
this DataBuffer and the returned ByteBuffer is shared; though
changes in the returned buffer's position
will not be reflected in the reading nor writing position of this data buffer.asByteBuffer 在接口中 DataBufferindex - the index at which to start the byte bufferlength - the length of the returned byte bufferpublic InputStream asInputStream()
DataBufferInputStream. Both data and read position are
shared between the returned stream and this data buffer. The underlying buffer will
not be released
when the input stream is closed.asInputStream 在接口中 DataBufferDataBuffer.asInputStream(boolean)public InputStream asInputStream(boolean releaseOnClose)
DataBufferInputStream. Both data and read position are
shared between the returned stream and this data buffer.asInputStream 在接口中 DataBufferreleaseOnClose - whether the underlying buffer will be
released when the input stream is
closed.public OutputStream asOutputStream()
DataBufferOutputStream. Both data and write position are
shared between the returned stream and this data buffer.asOutputStream 在接口中 DataBuffer