|
|
|
@ -36,8 +36,9 @@ import org.springframework.util.Assert; |
|
|
|
* <p>{@code DataBuffer}s has a separate {@linkplain #readPosition() read} and |
|
|
|
* <p>{@code DataBuffer}s has a separate {@linkplain #readPosition() read} and |
|
|
|
* {@linkplain #writePosition() write} position, as opposed to {@code ByteBuffer}'s |
|
|
|
* {@linkplain #writePosition() write} position, as opposed to {@code ByteBuffer}'s |
|
|
|
* single {@linkplain ByteBuffer#position() position}. As such, the {@code DataBuffer} |
|
|
|
* single {@linkplain ByteBuffer#position() position}. As such, the {@code DataBuffer} |
|
|
|
* does not require a {@linkplain ByteBuffer#flip() flip} to read after writing. In general, |
|
|
|
* does not require a {@linkplain ByteBuffer#flip() flip} to read after writing. |
|
|
|
* the following invariant holds for the read and write positions, and the capacity: |
|
|
|
* In general, the following invariant holds for the read and write positions, |
|
|
|
|
|
|
|
* and the capacity: |
|
|
|
* |
|
|
|
* |
|
|
|
* <blockquote> |
|
|
|
* <blockquote> |
|
|
|
* {@code 0} {@code <=} |
|
|
|
* {@code 0} {@code <=} |
|
|
|
@ -46,12 +47,13 @@ import org.springframework.util.Assert; |
|
|
|
* <i>capacity</i> |
|
|
|
* <i>capacity</i> |
|
|
|
* </blockquote> |
|
|
|
* </blockquote> |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The {@linkplain #capacity() capacity} of a {@code DataBuffer} is expanded on demand, |
|
|
|
* <p>The {@linkplain #capacity() capacity} of a {@code DataBuffer} is expanded on |
|
|
|
* similar to {@code StringBuilder}. |
|
|
|
* demand, similar to {@code StringBuilder}. |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>The main purpose of the {@code DataBuffer} abstraction is to provide a convenient wrapper |
|
|
|
* <p>The main purpose of the {@code DataBuffer} abstraction is to provide a |
|
|
|
* around {@link ByteBuffer} which is similar to Netty's {@link io.netty.buffer.ByteBuf} but |
|
|
|
* convenient wrapper around {@link ByteBuffer} which is similar to Netty's |
|
|
|
* can also be used on non-Netty platforms (i.e. Servlet containers). |
|
|
|
* {@link io.netty.buffer.ByteBuf} but can also be used on non-Netty platforms |
|
|
|
|
|
|
|
* (i.e. Servlet containers). |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Brian Clozel |
|
|
|
* @author Brian Clozel |
|
|
|
@ -113,8 +115,8 @@ public interface DataBuffer { |
|
|
|
* the current capacity, it will be expanded. |
|
|
|
* the current capacity, it will be expanded. |
|
|
|
* @param capacity the new capacity |
|
|
|
* @param capacity the new capacity |
|
|
|
* @return this buffer |
|
|
|
* @return this buffer |
|
|
|
* @deprecated as of 6.0, in favor of {@link #ensureWritable(int)}, which |
|
|
|
* @deprecated as of 6.0, in favor of {@link #ensureWritable(int)} |
|
|
|
* has different semantics |
|
|
|
* which has different semantics |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
DataBuffer capacity(int capacity); |
|
|
|
DataBuffer capacity(int capacity); |
|
|
|
@ -240,16 +242,16 @@ public interface DataBuffer { |
|
|
|
DataBuffer write(byte b); |
|
|
|
DataBuffer write(byte b); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Write the given source into this buffer, starting at the current writing position |
|
|
|
* Write the given source into this buffer, starting at the current writing |
|
|
|
* of this buffer. |
|
|
|
* position of this buffer. |
|
|
|
* @param source the bytes to be written into this buffer |
|
|
|
* @param source the bytes to be written into this buffer |
|
|
|
* @return this buffer |
|
|
|
* @return this buffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
DataBuffer write(byte[] source); |
|
|
|
DataBuffer write(byte[] source); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Write at most {@code length} bytes of the given source into this buffer, starting |
|
|
|
* Write at most {@code length} bytes of the given source into this buffer, |
|
|
|
* at the current writing position of this buffer. |
|
|
|
* starting at the current writing position of this buffer. |
|
|
|
* @param source the bytes to be written into this buffer |
|
|
|
* @param source the bytes to be written into this buffer |
|
|
|
* @param offset the index within {@code source} to start writing from |
|
|
|
* @param offset the index within {@code source} to start writing from |
|
|
|
* @param length the maximum number of bytes to be written from {@code source} |
|
|
|
* @param length the maximum number of bytes to be written from {@code source} |
|
|
|
@ -258,8 +260,8 @@ public interface DataBuffer { |
|
|
|
DataBuffer write(byte[] source, int offset, int length); |
|
|
|
DataBuffer write(byte[] source, int offset, int length); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Write one or more {@code DataBuffer}s to this buffer, starting at the current |
|
|
|
* Write one or more {@code DataBuffer}s to this buffer, starting at the |
|
|
|
* writing position. It is the responsibility of the caller to |
|
|
|
* current writing position. It is the responsibility of the caller to |
|
|
|
* {@linkplain DataBufferUtils#release(DataBuffer) release} the given data buffers. |
|
|
|
* {@linkplain DataBufferUtils#release(DataBuffer) release} the given data buffers. |
|
|
|
* @param buffers the byte buffers to write into this buffer |
|
|
|
* @param buffers the byte buffers to write into this buffer |
|
|
|
* @return this buffer |
|
|
|
* @return this buffer |
|
|
|
@ -267,8 +269,8 @@ public interface DataBuffer { |
|
|
|
DataBuffer write(DataBuffer... buffers); |
|
|
|
DataBuffer write(DataBuffer... buffers); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Write one or more {@link ByteBuffer} to this buffer, starting at the current |
|
|
|
* Write one or more {@link ByteBuffer} to this buffer, starting at the |
|
|
|
* writing position. |
|
|
|
* current writing position. |
|
|
|
* @param buffers the byte buffers to write into this buffer |
|
|
|
* @param buffers the byte buffers to write into this buffer |
|
|
|
* @return this buffer |
|
|
|
* @return this buffer |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -321,36 +323,37 @@ public interface DataBuffer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@code DataBuffer} whose contents is a shared subsequence of this |
|
|
|
* Create a new {@code DataBuffer} whose contents is a shared subsequence |
|
|
|
* data buffer's content. Data between this data buffer and the returned buffer is |
|
|
|
* of this data buffer's content. Data between this data buffer and the |
|
|
|
* shared; though changes in the returned buffer's position will not be reflected |
|
|
|
* returned buffer is shared; though changes in the returned buffer's |
|
|
|
* in the reading nor writing position of this data buffer. |
|
|
|
* position will not be reflected in the reading nor writing position |
|
|
|
|
|
|
|
* of this data buffer. |
|
|
|
* <p><strong>Note</strong> that this method will <strong>not</strong> call |
|
|
|
* <p><strong>Note</strong> that this method will <strong>not</strong> call |
|
|
|
* {@link DataBufferUtils#retain(DataBuffer)} on the resulting slice: the reference |
|
|
|
* {@link DataBufferUtils#retain(DataBuffer)} on the resulting slice: |
|
|
|
* count will not be increased. |
|
|
|
* the reference count will not be increased. |
|
|
|
* @param index the index at which to start the slice |
|
|
|
* @param index the index at which to start the slice |
|
|
|
* @param length the length of the slice |
|
|
|
* @param length the length of the slice |
|
|
|
* @return the specified slice of this data buffer |
|
|
|
* @return the specified slice of this data buffer |
|
|
|
* @deprecated as of 6.0, in favor of {@link #split(int)}, which |
|
|
|
* @deprecated as of 6.0, in favor of {@link #split(int)} |
|
|
|
* has different semantics |
|
|
|
* which has different semantics |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
DataBuffer slice(int index, int length); |
|
|
|
DataBuffer slice(int index, int length); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Create a new {@code DataBuffer} whose contents is a shared, retained subsequence of this |
|
|
|
* Create a new {@code DataBuffer} whose contents is a shared, retained subsequence |
|
|
|
* data buffer's content. Data between this data buffer and the returned buffer is |
|
|
|
* of this data buffer's content. Data between this data buffer and the returned |
|
|
|
* shared; though changes in the returned buffer's position will not be reflected |
|
|
|
* buffer is shared; though changes in the returned buffer's position will not be |
|
|
|
* in the reading nor writing position of this data buffer. |
|
|
|
* reflected in the reading nor writing position of this data buffer. |
|
|
|
* <p><strong>Note</strong> that unlike {@link #slice(int, int)}, this method |
|
|
|
* <p><strong>Note</strong> that unlike {@link #slice(int, int)}, this method |
|
|
|
* <strong>will</strong> call {@link DataBufferUtils#retain(DataBuffer)} (or equivalent) on the |
|
|
|
* <strong>will</strong> call {@link DataBufferUtils#retain(DataBuffer)} |
|
|
|
* resulting slice. |
|
|
|
* (or equivalent) on the resulting slice. |
|
|
|
* @param index the index at which to start the slice |
|
|
|
* @param index the index at which to start the slice |
|
|
|
* @param length the length of the slice |
|
|
|
* @param length the length of the slice |
|
|
|
* @return the specified, retained slice of this data buffer |
|
|
|
* @return the specified, retained slice of this data buffer |
|
|
|
* @since 5.2 |
|
|
|
* @since 5.2 |
|
|
|
* @deprecated as of 6.0, in favor of {@link #split(int)}, which |
|
|
|
* @deprecated as of 6.0, in favor of {@link #split(int)} |
|
|
|
* has different semantics |
|
|
|
* which has different semantics |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
default DataBuffer retainedSlice(int index, int length) { |
|
|
|
default DataBuffer retainedSlice(int index, int length) { |
|
|
|
@ -359,12 +362,10 @@ public interface DataBuffer { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Splits this data buffer into two at the given index. |
|
|
|
* Splits this data buffer into two at the given index. |
|
|
|
* |
|
|
|
|
|
|
|
* <p>Data that precedes the {@code index} will be returned in a new buffer, |
|
|
|
* <p>Data that precedes the {@code index} will be returned in a new buffer, |
|
|
|
* while this buffer will contain data that follows after {@code index}. |
|
|
|
* while this buffer will contain data that follows after {@code index}. |
|
|
|
* Memory between the two buffers is shared, but independent and cannot |
|
|
|
* Memory between the two buffers is shared, but independent and cannot |
|
|
|
* overlap (unlike {@link #slice(int, int) slice}). |
|
|
|
* overlap (unlike {@link #slice(int, int) slice}). |
|
|
|
* |
|
|
|
|
|
|
|
* <p>The {@linkplain #readPosition() read} and |
|
|
|
* <p>The {@linkplain #readPosition() read} and |
|
|
|
* {@linkplain #writePosition() write} position of the returned buffer are |
|
|
|
* {@linkplain #writePosition() write} position of the returned buffer are |
|
|
|
* truncated to fit within the buffers {@linkplain #capacity() capacity} if |
|
|
|
* truncated to fit within the buffers {@linkplain #capacity() capacity} if |
|
|
|
@ -384,22 +385,22 @@ public interface DataBuffer { |
|
|
|
* will not be reflected in the reading nor writing position of this data buffer. |
|
|
|
* will not be reflected in the reading nor writing position of this data buffer. |
|
|
|
* @return this data buffer as a byte buffer |
|
|
|
* @return this data buffer as a byte buffer |
|
|
|
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(ByteBuffer)}, |
|
|
|
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(ByteBuffer)}, |
|
|
|
* {@link #readableByteBuffers()}, or {@link #writableByteBuffers()}. |
|
|
|
* {@link #readableByteBuffers()} or {@link #writableByteBuffers()} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
ByteBuffer asByteBuffer(); |
|
|
|
ByteBuffer asByteBuffer(); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Expose a subsequence of this buffer's bytes as a {@link ByteBuffer}. Data between |
|
|
|
* Expose a subsequence of this buffer's bytes as a {@link ByteBuffer}. Data |
|
|
|
* this {@code DataBuffer} and the returned {@code ByteBuffer} is shared; though |
|
|
|
* between this {@code DataBuffer} and the returned {@code ByteBuffer} is shared; |
|
|
|
* changes in the returned buffer's {@linkplain ByteBuffer#position() position} |
|
|
|
* though changes in the returned buffer's {@linkplain ByteBuffer#position() position} |
|
|
|
* will not be reflected in the reading nor writing position of this data buffer. |
|
|
|
* will not be reflected in the reading nor writing position of this data buffer. |
|
|
|
* @param index the index at which to start the byte buffer |
|
|
|
* @param index the index at which to start the byte buffer |
|
|
|
* @param length the length of the returned byte buffer |
|
|
|
* @param length the length of the returned byte buffer |
|
|
|
* @return this data buffer as a byte buffer |
|
|
|
* @return this data buffer as a byte buffer |
|
|
|
* @since 5.0.1 |
|
|
|
* @since 5.0.1 |
|
|
|
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(int, ByteBuffer, int, int)}, |
|
|
|
* @deprecated as of 6.0, in favor of {@link #toByteBuffer(int, ByteBuffer, int, int)}, |
|
|
|
* {@link #readableByteBuffers()}, or {@link #writableByteBuffers()}. |
|
|
|
* {@link #readableByteBuffers()} or {@link #writableByteBuffers()} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
@Deprecated(since = "6.0") |
|
|
|
ByteBuffer asByteBuffer(int index, int length); |
|
|
|
ByteBuffer asByteBuffer(int index, int length); |
|
|
|
@ -553,6 +554,7 @@ public interface DataBuffer { |
|
|
|
void close(); |
|
|
|
void close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Process a range of bytes one by one. |
|
|
|
* Process a range of bytes one by one. |
|
|
|
* @since 6.2.12 |
|
|
|
* @since 6.2.12 |
|
|
|
@ -565,10 +567,9 @@ public interface DataBuffer { |
|
|
|
* should continue further. |
|
|
|
* should continue further. |
|
|
|
* @param b a byte from the {@link DataBuffer} |
|
|
|
* @param b a byte from the {@link DataBuffer} |
|
|
|
* @return {@code true} if processing should continue, |
|
|
|
* @return {@code true} if processing should continue, |
|
|
|
* or {@code false} if processing should stop at this element. |
|
|
|
* or {@code false} if processing should stop at this element |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean process(byte b); |
|
|
|
boolean process(byte b); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|