类 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
- 另请参阅:
-
方法概要
修饰符和类型方法说明Expose this buffer's bytes as aByteBuffer.asByteBuffer(int index, int length) Expose a subsequence of this buffer's bytes as aByteBuffer.intcapacity()Return the number of bytes that this buffer can contain.capacity(int capacity) Set the number of bytes that this buffer can contain.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.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.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.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.toString()Return a part of this buffer's data as a String using the specified charset.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... buffers) Write one or moreDataBuffers to this buffer, starting at the current writing position.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, ensureCapacity, retainedSlice, toByteBuffer, toString, write
-
方法详细资料
-
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
-
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
-
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
-
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- 参数:
buffers- 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
-
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.- 指定者:
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.- 指定者:
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
-
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
-
equals
-
hashCode
public int hashCode() -
toString
-