类 DefaultDataBuffer
- 所有已实现的接口:
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.
- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Juergen Hoeller, Brian Clozel, Harry Yang
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明private static final classprivate static class -
字段概要
字段修饰符和类型字段说明private ByteBufferprivate intprivate static final intprivate final DefaultDataBufferFactoryprivate static final intprivate intprivate int -
构造器概要
构造器限定符构造器说明privateDefaultDataBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) -
方法概要
修饰符和类型方法说明private static ByteBufferallocate(int capacity, boolean direct) Expose this buffer's bytes as aByteBuffer.asByteBuffer(int index, int length) Expose a subsequence of this buffer's bytes as aByteBuffer.private voidassertIndex(boolean expression, String format, Object... args) private intcalculateCapacity(int neededCapacity) Calculate the capacity of the buffer.intcapacity()Return the number of bytes that this buffer can contain.capacity(int capacity) Set the number of bytes that this buffer can contain.private voidcheckIndex(int index) private voidcheckIndex(int index, int length) private voidcheckLength(int length) ensureWritable(int length) Ensure that the current buffer has enoughDataBuffer.writableByteCount()to write the amount of data given as an argument.booleanfactory()Return theDataBufferFactorythat created this buffer.(专用程序包) static DefaultDataBufferfromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) (专用程序包) static DefaultDataBufferfromFilledByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) bytegetByte(int index) Read a single byte at the given index from this data buffer.Directly exposes the nativeByteBufferthat this buffer is based on also updating theByteBuffer'sposition and limit to match the currentreadPosition()andreadableByteCount().inthashCode()intindexOf(IntPredicate predicate, int fromIndex) Return the index of the first byte in this buffer that matches the given predicate.intlastIndexOf(IntPredicate predicate, int fromIndex) Return the index of the last byte in this buffer that matches the given predicate.byteread()Read a single byte from the current reading position from this data buffer.read(byte[] destination) Read this buffer's data into the specified destination, starting at the current reading position of this buffer.read(byte[] destination, int offset, int length) Read at mostlengthbytes of this buffer into the specified destination, starting at the current reading position of this buffer.Returns a closeable iterator over eachByteBufferin this data buffer that can be read.intReturn the number of bytes that can be read from this data buffer.intReturn the position from which this buffer will read.readPosition(int readPosition) Set the position from which this buffer will read.private voidsetCapacity(int newCapacity) private voidsetNativeBuffer(ByteBuffer byteBuffer) slice(int index, int length) Create a newDataBufferwhose contents is a shared subsequence of this data buffer's content.split(int index) Splits this data buffer into two at the given index.toByteBuffer(int index, int length) Returns aByteBufferrepresentation of a subsequence of this buffer's bytes.voidtoByteBuffer(int srcPos, ByteBuffer dest, int destPos, int length) Copies the given length from this data buffer into the given destinationByteBuffer, beginning at the given source position, and the given destination position in the destination byte buffer.toString()Return a part of this buffer's data as a String using the specified charset.Returns a closeable iterator over eachByteBufferin this data buffer that can be written to.intReturn the number of bytes that can be written to this data buffer.write(byte b) Write a single byte into this buffer at the current writing position.write(byte[] source) Write the given source into this buffer, starting at the current writing position of this buffer.write(byte[] source, int offset, int length) Write at mostlengthbytes of the given source into this buffer, starting at the current writing position of this buffer.write(DataBuffer... dataBuffers) Write one or moreDataBuffers to this buffer, starting at the current writing position.private voidwrite(ByteBuffer source) write(ByteBuffer... buffers) Write one or moreByteBufferto this buffer, starting at the current writing position.intReturn the position to which this buffer will write.writePosition(int writePosition) Set the position to which this buffer will write.从接口继承的方法 cn.taketoday.core.io.buffer.DataBuffer
asInputStream, asInputStream, asOutputStream, retainedSlice, toByteBuffer, toByteBuffer, toString, write
-
字段详细资料
-
构造器详细资料
-
DefaultDataBuffer
-
-
方法详细资料
-
fromFilledByteBuffer
static DefaultDataBuffer fromFilledByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) -
fromEmptyByteBuffer
static DefaultDataBuffer fromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) -
getNativeBuffer
Directly exposes the nativeByteBufferthat this buffer is based on also updating theByteBuffer'sposition and limit to match the currentreadPosition()andreadableByteCount().- 返回:
- the wrapped byte buffer
-
setNativeBuffer
-
factory
从接口复制的说明:DataBufferReturn theDataBufferFactorythat created this buffer.- 指定者:
factory在接口中DataBuffer- 返回:
- the creating buffer factory
-
indexOf
从接口复制的说明:DataBufferReturn 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-1if none match
-
lastIndexOf
从接口复制的说明:DataBufferReturn 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-1if none match
-
readableByteCount
public int readableByteCount()从接口复制的说明:DataBufferReturn the number of bytes that can be read from this data buffer.- 指定者:
readableByteCount在接口中DataBuffer- 返回:
- the readable byte count
-
writableByteCount
public int writableByteCount()从接口复制的说明:DataBufferReturn the number of bytes that can be written to this data buffer.- 指定者:
writableByteCount在接口中DataBuffer- 返回:
- the writable byte count
-
readPosition
public int readPosition()从接口复制的说明:DataBufferReturn the position from which this buffer will read.- 指定者:
readPosition在接口中DataBuffer- 返回:
- the read position
-
readPosition
从接口复制的说明:DataBufferSet the position from which this buffer will read.- 指定者:
readPosition在接口中DataBuffer- 参数:
readPosition- the new read position- 返回:
- this buffer
-
writePosition
public int writePosition()从接口复制的说明:DataBufferReturn the position to which this buffer will write.- 指定者:
writePosition在接口中DataBuffer- 返回:
- the write position
-
writePosition
从接口复制的说明:DataBufferSet the position to which this buffer will write.- 指定者:
writePosition在接口中DataBuffer- 参数:
writePosition- the new write position- 返回:
- this buffer
-
capacity
public int capacity()从接口复制的说明:DataBufferReturn the number of bytes that this buffer can contain.- 指定者:
capacity在接口中DataBuffer- 返回:
- the capacity
-
capacity
从接口复制的说明:DataBufferSet 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
- 另请参阅:
-
setCapacity
private void setCapacity(int newCapacity) -
ensureWritable
从接口复制的说明:DataBufferEnsure 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.- 指定者:
ensureWritable在接口中DataBuffer- 参数:
length- the writable capacity to check for- 返回:
- this buffer
-
allocate
-
getByte
public byte getByte(int index) 从接口复制的说明:DataBufferRead 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
-
read
public byte read()从接口复制的说明:DataBufferRead a single byte from the current reading position from this data buffer.- 指定者:
read在接口中DataBuffer- 返回:
- the byte at this buffer's current reading position
-
read
从接口复制的说明:DataBufferRead 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
从接口复制的说明:DataBufferRead at mostlengthbytes 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 withindestinationof the first byte to be writtenlength- the maximum number of bytes to be written indestination- 返回:
- this buffer
-
write
从接口复制的说明:DataBufferWrite a single byte into this buffer at the current writing position.- 指定者:
write在接口中DataBuffer- 参数:
b- the byte to be written- 返回:
- this buffer
-
write
从接口复制的说明:DataBufferWrite 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
从接口复制的说明:DataBufferWrite at mostlengthbytes 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 withinsourceto start writing fromlength- the maximum number of bytes to be written fromsource- 返回:
- this buffer
-
write
从接口复制的说明:DataBufferWrite one or moreDataBuffers to this buffer, starting at the current writing position. It is the responsibility of the caller to release the given data buffers.- 指定者:
write在接口中DataBuffer- 参数:
dataBuffers- the byte buffers to write into this buffer- 返回:
- this buffer
-
write
从接口复制的说明:DataBufferWrite one or moreByteBufferto this buffer, starting at the current writing position.- 指定者:
write在接口中DataBuffer- 参数:
buffers- the byte buffers to write into this buffer- 返回:
- this buffer
-
write
-
slice
从接口复制的说明:DataBufferCreate a newDataBufferwhose 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
- 另请参阅:
-
split
从接口复制的说明:DataBufferSplits this data buffer into two at the given index.Data that precedes the
indexwill be returned in a new buffer, while this buffer will contain data that follows afterindex. Memory between the two buffers is shared, but independent and cannot overlap (unlikeslice).The read and write position of the returned buffer are truncated to fit within the buffers capacity if necessary. The positions of this buffer are set to
0if they are smaller thanindex.- 指定者:
split在接口中DataBuffer- 参数:
index- the index at which it should be split- 返回:
- a new data buffer, containing the bytes from index
0toindex
-
asByteBuffer
从接口复制的说明:DataBufferExpose this buffer's bytes as aByteBuffer. Data between thisDataBufferand the returnedByteBufferis shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.DataBuffer.toByteBuffer(), which does not share data and returns a copy.- 指定者:
asByteBuffer在接口中DataBuffer- 返回:
- this data buffer as a byte buffer
-
asByteBuffer
从接口复制的说明:DataBufferExpose a subsequence of this buffer's bytes as aByteBuffer. Data between thisDataBufferand the returnedByteBufferis shared; though changes in the returned buffer's position will not be reflected in the reading nor writing position of this data buffer.in favor of
DataBuffer.toByteBuffer(int, int), which does not share data and returns a copy.- 指定者:
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
-
toByteBuffer
从接口复制的说明:DataBufferReturns aByteBufferrepresentation of a subsequence of this buffer's bytes. Data between thisDataBufferand the returnedByteBufferis not shared.- 指定者:
toByteBuffer在接口中DataBuffer- 返回:
- this data buffer as a byte buffer
-
toByteBuffer
从接口复制的说明:DataBufferCopies the given length from this data buffer into the given destinationByteBuffer, beginning at the given source position, and the given destination position in the destination byte buffer.- 指定者:
toByteBuffer在接口中DataBuffer- 参数:
srcPos- the position of this data buffer from where copying should startdest- the destination byte bufferdestPos- the position indestto where copying should startlength- the amount of data to copy
-
readableByteBuffers
从接口复制的说明:DataBufferReturns a closeable iterator over eachByteBufferin this data buffer that can be read. Calling this method is more efficient thanDataBuffer.toByteBuffer(), as no data is copied. However, the byte buffers provided can only be used during the iteration.Note that the returned iterator must be used in a try-with-resources clause or explicitly closed.
- 指定者:
readableByteBuffers在接口中DataBuffer- 返回:
- a closeable iterator over the readable byte buffers contained in this data buffer
-
writableByteBuffers
从接口复制的说明:DataBufferReturns a closeable iterator over eachByteBufferin this data buffer that can be written to. The byte buffers provided can only be used during the iteration.Note that the returned iterator must be used in a try-with-resources clause or explicitly closed.
- 指定者:
writableByteBuffers在接口中DataBuffer- 返回:
- a closeable iterator over the writable byte buffers contained in this data buffer
-
toString
从接口复制的说明:DataBufferReturn 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
-
calculateCapacity
private int calculateCapacity(int neededCapacity) Calculate the capacity of the buffer.- 另请参阅:
-
AbstractByteBufAllocator.calculateNewCapacity(int, int)
-
equals
-
hashCode
public int hashCode() -
toString
-
checkIndex
private void checkIndex(int index, int length) -
checkIndex
private void checkIndex(int index) -
checkLength
private void checkLength(int length) -
assertIndex
-