Class DataBufferWrapper
- All Implemented Interfaces:
DataBuffer
DataBuffer
interface
that can be overridden to adapt the delegate.
These methods default to calling through to the wrapped delegate object.
- Since:
- 5.2
- Author:
- Arjen Poutsma
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.core.io.buffer.DataBuffer
DataBuffer.ByteBufferIterator
-
Constructor Summary
ConstructorDescriptionDataBufferWrapper
(DataBuffer delegate) Create a newDataBufferWrapper
that wraps the given buffer. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.asByteBuffer
(int index, int length) Deprecated.Expose this buffer's data as anInputStream
.asInputStream
(boolean releaseOnClose) Expose this buffer's data as anInputStream
.Expose this buffer's data as anOutputStream
.int
capacity()
Return the number of bytes that this buffer can contain.capacity
(int capacity) Deprecated.Return the wrapped delegate.ensureCapacity
(int capacity) Deprecated.ensureWritable
(int capacity) Ensure that the current buffer has enoughDataBuffer.writableByteCount()
to write the amount of data given as an argument.factory()
Return theDataBufferFactory
that created this buffer.byte
getByte
(int index) Read a single byte at the given index from this data buffer.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.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 mostlength
bytes of this buffer into the specified destination, starting at the current reading position of this buffer.Returns a closeable iterator over eachByteBuffer
in this data buffer that can be read.int
Return the number of bytes that can be read from this data buffer.int
Return the position from which this buffer will read.readPosition
(int readPosition) Set the position from which this buffer will read.retainedSlice
(int index, int length) Deprecated.slice
(int index, int length) Deprecated.split
(int index) Splits this data buffer into two at the given index.Deprecated.toByteBuffer
(int index, int length) Deprecated.void
toByteBuffer
(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.void
toByteBuffer
(ByteBuffer dest) Copies this entire data buffer into the given destinationByteBuffer
, beginning at the current reading position, and the current position of destination byte buffer.Return a part of this buffer's data as a String using the specified charset.Return this buffer's data a String using the specified charset.Returns a closeable iterator over eachByteBuffer
in this data buffer that can be written to.int
Return 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 mostlength
bytes of the given source into this buffer, starting at the current writing position of this buffer.write
(CharSequence charSequence, Charset charset) Write the givenCharSequence
using the givenCharset
, starting at the current writing position.write
(ByteBuffer... buffers) Write one or moreByteBuffer
to this buffer, starting at the current writing position.write
(DataBuffer... buffers) Write one or moreDataBuffer
s to this buffer, starting at the current writing position.int
Return the position to which this buffer will write.writePosition
(int writePosition) Set the position to which this buffer will write.
-
Constructor Details
-
DataBufferWrapper
Create a newDataBufferWrapper
that wraps the given buffer.- Parameters:
delegate
- the buffer to wrap
-
-
Method Details
-
dataBuffer
Return the wrapped delegate. -
factory
Description copied from interface:DataBuffer
Return theDataBufferFactory
that created this buffer.- Specified by:
factory
in interfaceDataBuffer
- Returns:
- the creating buffer factory
-
indexOf
Description copied from interface:DataBuffer
Return the index of the first byte in this buffer that matches the given predicate.- Specified by:
indexOf
in interfaceDataBuffer
- Parameters:
predicate
- the predicate to matchfromIndex
- the index to start the search from- Returns:
- the index of the first byte that matches
predicate
; or-1
if none match
-
lastIndexOf
Description copied from interface:DataBuffer
Return the index of the last byte in this buffer that matches the given predicate.- Specified by:
lastIndexOf
in interfaceDataBuffer
- Parameters:
predicate
- the predicate to matchfromIndex
- the index to start the search from- Returns:
- the index of the last byte that matches
predicate
; or-1
if none match
-
readableByteCount
public int readableByteCount()Description copied from interface:DataBuffer
Return the number of bytes that can be read from this data buffer.- Specified by:
readableByteCount
in interfaceDataBuffer
- Returns:
- the readable byte count
-
writableByteCount
public int writableByteCount()Description copied from interface:DataBuffer
Return the number of bytes that can be written to this data buffer.- Specified by:
writableByteCount
in interfaceDataBuffer
- Returns:
- the writable byte count
-
capacity
public int capacity()Description copied from interface:DataBuffer
Return the number of bytes that this buffer can contain.- Specified by:
capacity
in interfaceDataBuffer
- Returns:
- the capacity
-
capacity
Deprecated.Description copied from interface: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.
- Specified by:
capacity
in interfaceDataBuffer
- Parameters:
capacity
- the new capacity- Returns:
- this buffer
-
ensureCapacity
Deprecated.Description copied from interface: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.- Specified by:
ensureCapacity
in interfaceDataBuffer
- Parameters:
capacity
- the writable capacity to check for- Returns:
- this buffer
-
ensureWritable
Description copied from interface: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.- Specified by:
ensureWritable
in interfaceDataBuffer
- Parameters:
capacity
- the writable capacity to check for- Returns:
- this buffer
-
readPosition
public int readPosition()Description copied from interface:DataBuffer
Return the position from which this buffer will read.- Specified by:
readPosition
in interfaceDataBuffer
- Returns:
- the read position
-
readPosition
Description copied from interface:DataBuffer
Set the position from which this buffer will read.- Specified by:
readPosition
in interfaceDataBuffer
- Parameters:
readPosition
- the new read position- Returns:
- this buffer
-
writePosition
public int writePosition()Description copied from interface:DataBuffer
Return the position to which this buffer will write.- Specified by:
writePosition
in interfaceDataBuffer
- Returns:
- the write position
-
writePosition
Description copied from interface:DataBuffer
Set the position to which this buffer will write.- Specified by:
writePosition
in interfaceDataBuffer
- Parameters:
writePosition
- the new write position- Returns:
- this buffer
-
getByte
public byte getByte(int index) Description copied from interface:DataBuffer
Read a single byte at the given index from this data buffer.- Specified by:
getByte
in interfaceDataBuffer
- Parameters:
index
- the index at which the byte will be read- Returns:
- the byte at the given index
-
read
public byte read()Description copied from interface:DataBuffer
Read a single byte from the current reading position from this data buffer.- Specified by:
read
in interfaceDataBuffer
- Returns:
- the byte at this buffer's current reading position
-
read
Description copied from interface:DataBuffer
Read this buffer's data into the specified destination, starting at the current reading position of this buffer.- Specified by:
read
in interfaceDataBuffer
- Parameters:
destination
- the array into which the bytes are to be written- Returns:
- this buffer
-
read
Description copied from interface:DataBuffer
Read at mostlength
bytes of this buffer into the specified destination, starting at the current reading position of this buffer.- Specified by:
read
in interfaceDataBuffer
- Parameters:
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
- Returns:
- this buffer
-
write
Description copied from interface:DataBuffer
Write a single byte into this buffer at the current writing position.- Specified by:
write
in interfaceDataBuffer
- Parameters:
b
- the byte to be written- Returns:
- this buffer
-
write
Description copied from interface:DataBuffer
Write the given source into this buffer, starting at the current writing position of this buffer.- Specified by:
write
in interfaceDataBuffer
- Parameters:
source
- the bytes to be written into this buffer- Returns:
- this buffer
-
write
Description copied from interface:DataBuffer
Write at mostlength
bytes of the given source into this buffer, starting at the current writing position of this buffer.- Specified by:
write
in interfaceDataBuffer
- Parameters:
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
- Returns:
- this buffer
-
write
Description copied from interface: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.- Specified by:
write
in interfaceDataBuffer
- Parameters:
buffers
- the byte buffers to write into this buffer- Returns:
- this buffer
-
write
Description copied from interface:DataBuffer
Write one or moreByteBuffer
to this buffer, starting at the current writing position.- Specified by:
write
in interfaceDataBuffer
- Parameters:
buffers
- the byte buffers to write into this buffer- Returns:
- this buffer
-
write
Description copied from interface:DataBuffer
Write the givenCharSequence
using the givenCharset
, starting at the current writing position.- Specified by:
write
in interfaceDataBuffer
- Parameters:
charSequence
- the char sequence to write into this buffercharset
- the charset to encode the char sequence with- Returns:
- this buffer
-
slice
Deprecated.Description copied from interface: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.- Specified by:
slice
in interfaceDataBuffer
- Parameters:
index
- the index at which to start the slicelength
- the length of the slice- Returns:
- the specified slice of this data buffer
-
retainedSlice
Deprecated.Description copied from interface: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.- Specified by:
retainedSlice
in interfaceDataBuffer
- Parameters:
index
- the index at which to start the slicelength
- the length of the slice- Returns:
- the specified, retained slice of this data buffer
-
split
Description copied from interface:DataBuffer
Splits this data buffer into two at the given index.Data that precedes the
index
will 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
0
if they are smaller thanindex
.- Specified by:
split
in interfaceDataBuffer
- Parameters:
index
- the index at which it should be split- Returns:
- a new data buffer, containing the bytes from index
0
toindex
-
asByteBuffer
Deprecated.Description copied from interface: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.- Specified by:
asByteBuffer
in interfaceDataBuffer
- Returns:
- this data buffer as a byte buffer
-
asByteBuffer
Deprecated.Description copied from interface: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.- Specified by:
asByteBuffer
in interfaceDataBuffer
- Parameters:
index
- the index at which to start the byte bufferlength
- the length of the returned byte buffer- Returns:
- this data buffer as a byte buffer
-
toByteBuffer
Deprecated.Description copied from interface:DataBuffer
Returns aByteBuffer
representation of this data buffer. Data between thisDataBuffer
and the returnedByteBuffer
is not shared.- Specified by:
toByteBuffer
in interfaceDataBuffer
- Returns:
- this data buffer as a byte buffer
- See Also:
-
toByteBuffer
Deprecated.Description copied from interface:DataBuffer
Returns aByteBuffer
representation of a subsequence of this buffer's bytes. Data between thisDataBuffer
and the returnedByteBuffer
is not shared.- Specified by:
toByteBuffer
in interfaceDataBuffer
- Returns:
- this data buffer as a byte buffer
- See Also:
-
toByteBuffer
Description copied from interface:DataBuffer
Copies this entire data buffer into the given destinationByteBuffer
, beginning at the current reading position, and the current position of destination byte buffer.- Specified by:
toByteBuffer
in interfaceDataBuffer
- Parameters:
dest
- the destination byte buffer
-
toByteBuffer
Description copied from interface:DataBuffer
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.- Specified by:
toByteBuffer
in interfaceDataBuffer
- Parameters:
srcPos
- the position of this data buffer from where copying should startdest
- the destination byte bufferdestPos
- the position indest
to where copying should startlength
- the amount of data to copy
-
readableByteBuffers
Description copied from interface:DataBuffer
Returns a closeable iterator over eachByteBuffer
in 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.
- Specified by:
readableByteBuffers
in interfaceDataBuffer
- Returns:
- a closeable iterator over the readable byte buffers contained in this data buffer
-
writableByteBuffers
Description copied from interface:DataBuffer
Returns a closeable iterator over eachByteBuffer
in 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.
- Specified by:
writableByteBuffers
in interfaceDataBuffer
- Returns:
- a closeable iterator over the writable byte buffers contained in this data buffer
-
asInputStream
Description copied from interface: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.- Specified by:
asInputStream
in interfaceDataBuffer
- Returns:
- this data buffer as an input stream
- See Also:
-
asInputStream
Description copied from interface:DataBuffer
Expose this buffer's data as anInputStream
. Both data and read position are shared between the returned stream and this data buffer.- Specified by:
asInputStream
in interfaceDataBuffer
- Parameters:
releaseOnClose
- whether the underlying buffer will be released when the input stream is closed.- Returns:
- this data buffer as an input stream
-
asOutputStream
Description copied from interface:DataBuffer
Expose this buffer's data as anOutputStream
. Both data and write position are shared between the returned stream and this data buffer.- Specified by:
asOutputStream
in interfaceDataBuffer
- Returns:
- this data buffer as an output stream
-
toString
Description copied from interface:DataBuffer
Return this buffer's data a String using the specified charset. Default implementation delegates totoString(readPosition(), readableByteCount(), charset)
.- Specified by:
toString
in interfaceDataBuffer
- Parameters:
charset
- the character set to use- Returns:
- a string representation of all this buffers data
-
toString
Description copied from interface:DataBuffer
Return a part of this buffer's data as a String using the specified charset.- Specified by:
toString
in interfaceDataBuffer
- Parameters:
index
- the index at which to start the stringlength
- the number of bytes to use for the stringcharset
- the charset to use- Returns:
- a string representation of a part of this buffers data
-