类 NettyDataBuffer
- java.lang.Object
- org.springframework.core.io.buffer.NettyDataBuffer
- 所有已实现的接口:
DataBuffer
,PooledDataBuffer
public class NettyDataBuffer extends Object implements PooledDataBuffer
Implementation of theDataBuffer
interface that wraps a NettyByteBuf
. Typically constructed withNettyDataBufferFactory
.- 从以下版本开始:
- 5.0
- 作者:
- Arjen Poutsma, Brian Clozel
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 ByteBuffer
asByteBuffer()
Expose this buffer's bytes as aByteBuffer
.ByteBuffer
asByteBuffer(int index, int length)
Expose a subsequence of this buffer's bytes as aByteBuffer
.InputStream
asInputStream()
Expose this buffer's data as anInputStream
.InputStream
asInputStream(boolean releaseOnClose)
Expose this buffer's data as anInputStream
.OutputStream
asOutputStream()
Expose this buffer's data as anOutputStream
.int
capacity()
Return the number of bytes that this buffer can contain.NettyDataBuffer
capacity(int capacity)
Set the number of bytes that this buffer can contain.DataBuffer
ensureCapacity(int capacity)
Ensure that the current buffer has enoughDataBuffer.writableByteCount()
to write the amount of data given as an argument.boolean
equals(Object other)
NettyDataBufferFactory
factory()
Return theDataBufferFactory
that created this buffer.byte
getByte(int index)
Read a single byte at the given index from this data buffer.io.netty.buffer.ByteBuf
getNativeBuffer()
Directly exposes the nativeByteBuf
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.boolean
isAllocated()
Returntrue
if this buffer is allocated;false
if it has been deallocated.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.NettyDataBuffer
read(byte[] destination)
Read this buffer's data into the specified destination, starting at the current reading position of this buffer.NettyDataBuffer
read(byte[] destination, int offset, int length)
Read at mostlength
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.NettyDataBuffer
readPosition(int readPosition)
Set the position from which this buffer will read.boolean
release()
Decrease the reference count for this buffer by one, and deallocate it once the count reaches zero.PooledDataBuffer
retain()
Increase the reference count for this buffer by one.NettyDataBuffer
retainedSlice(int index, int length)
Create a newDataBuffer
whose contents is a shared, retained subsequence of this data buffer's content.NettyDataBuffer
slice(int index, int length)
Create a newDataBuffer
whose contents is a shared subsequence of this data buffer's content.String
toString()
String
toString(int index, int length, Charset charset)
Return a part of this buffer's data as a String using the specified charset.String
toString(Charset charset)
Return this buffer's data a String using the specified charset.int
writableByteCount()
Return the number of bytes that can be written to this data buffer.NettyDataBuffer
write(byte b)
Write a single byte into this buffer at the current writing position.NettyDataBuffer
write(byte[] source)
Write the given source into this buffer, starting at the current writing position of this buffer.NettyDataBuffer
write(byte[] source, int offset, int length)
Write at mostlength
bytes of the given source into this buffer, starting at the current writing position of this buffer.NettyDataBuffer
write(io.netty.buffer.ByteBuf... byteBufs)
Writes one or more NettyByteBufs
to this buffer, starting at the current writing position.DataBuffer
write(CharSequence charSequence, Charset charset)
Write the givenCharSequence
using the givenCharset
, starting at the current writing position.NettyDataBuffer
write(ByteBuffer... buffers)
Write one or moreByteBuffer
to this buffer, starting at the current writing position.NettyDataBuffer
write(DataBuffer... buffers)
Write one or moreDataBuffer
s to this buffer, starting at the current writing position.int
writePosition()
Return the position to which this buffer will write.NettyDataBuffer
writePosition(int writePosition)
Set the position to which this buffer will write.
方法详细资料
getNativeBuffer
public io.netty.buffer.ByteBuf getNativeBuffer()
Directly exposes the nativeByteBuf
that this buffer is based on.- 返回:
- the wrapped byte buffer
factory
public NettyDataBufferFactory factory()
从接口复制的说明:DataBuffer
Return theDataBufferFactory
that created this buffer.- 指定者:
factory
在接口中DataBuffer
- 返回:
- the creating buffer factory
indexOf
public int indexOf(IntPredicate predicate, int fromIndex)
从接口复制的说明:DataBuffer
Return the index of the first byte in this buffer that matches the given predicate.- 指定者:
indexOf
在接口中DataBuffer
- 参数:
predicate
- the predicate to matchfromIndex
- the index to start the search from- 返回:
- the index of the first byte that matches
predicate
; or-1
if none match
lastIndexOf
public int lastIndexOf(IntPredicate predicate, int fromIndex)
从接口复制的说明:DataBuffer
Return the index of the last byte in this buffer that matches the given predicate.- 指定者:
lastIndexOf
在接口中DataBuffer
- 参数:
predicate
- the predicate to matchfromIndex
- the index to start the search from- 返回:
- the index of the last byte that matches
predicate
; or-1
if none match
readableByteCount
public int readableByteCount()
从接口复制的说明:DataBuffer
Return the number of bytes that can be read from this data buffer.- 指定者:
readableByteCount
在接口中DataBuffer
- 返回:
- the readable byte count
writableByteCount
public int writableByteCount()
从接口复制的说明:DataBuffer
Return the number of bytes that can be written to this data buffer.- 指定者:
writableByteCount
在接口中DataBuffer
- 返回:
- the writable byte count
readPosition
public int readPosition()
从接口复制的说明:DataBuffer
Return the position from which this buffer will read.- 指定者:
readPosition
在接口中DataBuffer
- 返回:
- the read position
readPosition
public NettyDataBuffer readPosition(int readPosition)
从接口复制的说明:DataBuffer
Set the position from which this buffer will read.- 指定者:
readPosition
在接口中DataBuffer
- 参数:
readPosition
- the new read position- 返回:
- this buffer
writePosition
public int writePosition()
从接口复制的说明:DataBuffer
Return the position to which this buffer will write.- 指定者:
writePosition
在接口中DataBuffer
- 返回:
- the write position
writePosition
public NettyDataBuffer writePosition(int writePosition)
从接口复制的说明:DataBuffer
Set the position to which this buffer will write.- 指定者:
writePosition
在接口中DataBuffer
- 参数:
writePosition
- the new write position- 返回:
- this buffer
getByte
public byte getByte(int index)
从接口复制的说明:DataBuffer
Read a single byte at the given index from this data buffer.- 指定者:
getByte
在接口中DataBuffer
- 参数:
index
- the index at which the byte will be read- 返回:
- the byte at the given index
capacity
public int capacity()
从接口复制的说明:DataBuffer
Return the number of bytes that this buffer can contain.- 指定者:
capacity
在接口中DataBuffer
- 返回:
- the capacity
capacity
public NettyDataBuffer capacity(int capacity)
从接口复制的说明:DataBuffer
Set the number of bytes that this buffer can contain.If 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
在接口中DataBuffer
- 参数:
capacity
- the new capacity- 返回:
- this buffer
ensureCapacity
public DataBuffer ensureCapacity(int capacity)
从接口复制的说明:DataBuffer
Ensure that the current buffer has enoughDataBuffer.writableByteCount()
to write the amount of data given as an argument. If not, the missing capacity will be added to the buffer.- 指定者:
ensureCapacity
在接口中DataBuffer
- 参数:
capacity
- the writable capacity to check for- 返回:
- this buffer
read
public byte read()
从接口复制的说明:DataBuffer
Read a single byte from the current reading position from this data buffer.- 指定者:
read
在接口中DataBuffer
- 返回:
- the byte at this buffer's current reading position
read
public NettyDataBuffer read(byte[] destination)
从接口复制的说明:DataBuffer
Read this buffer's data into the specified destination, starting at the current reading position of this buffer.- 指定者:
read
在接口中DataBuffer
- 参数:
destination
- the array into which the bytes are to be written- 返回:
- this buffer
read
public NettyDataBuffer read(byte[] destination, int offset, int length)
从接口复制的说明:DataBuffer
Read at mostlength
bytes of this buffer into the specified destination, starting at the current reading position of this buffer.- 指定者:
read
在接口中DataBuffer
- 参数:
destination
- the array into which the bytes are to be writtenoffset
- the index withindestination
of the first byte to be writtenlength
- the maximum number of bytes to be written indestination
- 返回:
- this buffer
write
public NettyDataBuffer write(byte b)
从接口复制的说明:DataBuffer
Write a single byte into this buffer at the current writing position.- 指定者:
write
在接口中DataBuffer
- 参数:
b
- the byte to be written- 返回:
- this buffer
write
public NettyDataBuffer write(byte[] source)
从接口复制的说明:DataBuffer
Write the given source into this buffer, starting at the current writing position of this buffer.- 指定者:
write
在接口中DataBuffer
- 参数:
source
- the bytes to be written into this buffer- 返回:
- this buffer
write
public NettyDataBuffer write(byte[] source, int offset, int length)
从接口复制的说明:DataBuffer
Write at mostlength
bytes of the given source into this buffer, starting at the current writing position of this buffer.- 指定者:
write
在接口中DataBuffer
- 参数:
source
- the bytes to be written into this bufferoffset
- the index withinsource
to start writing fromlength
- the maximum number of bytes to be written fromsource
- 返回:
- this buffer
write
public NettyDataBuffer write(DataBuffer... buffers)
从接口复制的说明:DataBuffer
Write one or moreDataBuffer
s to this buffer, starting at the current writing position. It is the responsibility of the caller to release the given data buffers.- 指定者:
write
在接口中DataBuffer
- 参数:
buffers
- the byte buffers to write into this buffer- 返回:
- this buffer
write
public NettyDataBuffer write(ByteBuffer... buffers)
从接口复制的说明:DataBuffer
Write one or moreByteBuffer
to this buffer, starting at the current writing position.- 指定者:
write
在接口中DataBuffer
- 参数:
buffers
- the byte buffers to write into this buffer- 返回:
- this buffer
write
public NettyDataBuffer write(io.netty.buffer.ByteBuf... byteBufs)
Writes one or more NettyByteBufs
to this buffer, starting at the current writing position.- 参数:
byteBufs
- the buffers to write into this buffer- 返回:
- this buffer
write
public DataBuffer write(CharSequence charSequence, Charset charset)
从接口复制的说明:DataBuffer
Write the givenCharSequence
using the givenCharset
, starting at the current writing position.- 指定者:
write
在接口中DataBuffer
- 参数:
charSequence
- the char sequence to write into this buffercharset
- the charset to encode the char sequence with- 返回:
- this buffer
slice
public NettyDataBuffer slice(int index, int length)
从接口复制的说明:DataBuffer
Create a newDataBuffer
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.Note that this method will not call
DataBufferUtils.retain(DataBuffer)
on the resulting slice: the reference count will not be increased.- 指定者:
slice
在接口中DataBuffer
- 参数:
index
- the index at which to start the slicelength
- the length of the slice- 返回:
- the specified slice of this data buffer
retainedSlice
public NettyDataBuffer retainedSlice(int index, int length)
从接口复制的说明:DataBuffer
Create a newDataBuffer
whose contents is a shared, retained 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.Note that unlike
DataBuffer.slice(int, int)
, this method will callDataBufferUtils.retain(DataBuffer)
(or equivalent) on the resulting slice.- 指定者:
retainedSlice
在接口中DataBuffer
- 参数:
index
- the index at which to start the slicelength
- the length of the slice- 返回:
- the specified, retained slice of this data buffer
asByteBuffer
public ByteBuffer asByteBuffer()
从接口复制的说明:DataBuffer
Expose this buffer's bytes as aByteBuffer
. Data between thisDataBuffer
and the returnedByteBuffer
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
在接口中DataBuffer
- 返回:
- this data buffer as a byte buffer
asByteBuffer
public ByteBuffer asByteBuffer(int index, int length)
从接口复制的说明:DataBuffer
Expose a subsequence of this buffer's bytes as aByteBuffer
. Data between thisDataBuffer
and the returnedByteBuffer
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
在接口中DataBuffer
- 参数:
index
- the index at which to start the byte bufferlength
- the length of the returned byte buffer- 返回:
- this data buffer as a byte buffer
asInputStream
public InputStream asInputStream()
从接口复制的说明:DataBuffer
Expose this buffer's data as anInputStream
. 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
在接口中DataBuffer
- 返回:
- this data buffer as an input stream
- 另请参阅:
DataBuffer.asInputStream(boolean)
asInputStream
public InputStream asInputStream(boolean releaseOnClose)
从接口复制的说明:DataBuffer
Expose this buffer's data as anInputStream
. Both data and read position are shared between the returned stream and this data buffer.- 指定者:
asInputStream
在接口中DataBuffer
- 参数:
releaseOnClose
- whether the underlying buffer will be released when the input stream is closed.- 返回:
- this data buffer as an input stream
asOutputStream
public OutputStream asOutputStream()
从接口复制的说明:DataBuffer
Expose this buffer's data as anOutputStream
. Both data and write position are shared between the returned stream and this data buffer.- 指定者:
asOutputStream
在接口中DataBuffer
- 返回:
- this data buffer as an output stream
toString
public String toString(Charset charset)
从接口复制的说明:DataBuffer
Return this buffer's data a String using the specified charset. Default implementation delegates totoString(readPosition(), readableByteCount(), charset)
.- 指定者:
toString
在接口中DataBuffer
- 参数:
charset
- the character set to use- 返回:
- a string representation of all this buffers data
toString
public String toString(int index, int length, Charset charset)
从接口复制的说明:DataBuffer
Return a part of this buffer's data as a String using the specified charset.- 指定者:
toString
在接口中DataBuffer
- 参数:
index
- the index at which to start the stringlength
- the number of bytes to use for the stringcharset
- the charset to use- 返回:
- a string representation of a part of this buffers data
isAllocated
public boolean isAllocated()
从接口复制的说明:PooledDataBuffer
Returntrue
if this buffer is allocated;false
if it has been deallocated.- 指定者:
isAllocated
在接口中PooledDataBuffer
retain
public PooledDataBuffer retain()
从接口复制的说明:PooledDataBuffer
Increase the reference count for this buffer by one.- 指定者:
retain
在接口中PooledDataBuffer
- 返回:
- this buffer
release
public boolean release()
从接口复制的说明:PooledDataBuffer
Decrease the reference count for this buffer by one, and deallocate it once the count reaches zero.- 指定者:
release
在接口中PooledDataBuffer
- 返回:
true
if the buffer was deallocated;false
otherwise