private static class UndertowServerHttpRequest.UndertowDataBuffer extends java.lang.Object implements PooledDataBuffer
Modifier and Type | Field and Description |
---|---|
private DataBuffer |
dataBuffer |
private PooledByteBuffer |
pooledByteBuffer |
Constructor and Description |
---|
UndertowDataBuffer(DataBuffer dataBuffer,
PooledByteBuffer pooledByteBuffer) |
Modifier and Type | Method and Description |
---|---|
java.nio.ByteBuffer |
asByteBuffer()
Expose this buffer's bytes as a
ByteBuffer . |
java.nio.ByteBuffer |
asByteBuffer(int index,
int length)
Expose a subsequence of this buffer's bytes as a
ByteBuffer . |
java.io.InputStream |
asInputStream()
Expose this buffer's data as an
InputStream . |
java.io.InputStream |
asInputStream(boolean releaseOnClose)
Expose this buffer's data as an
InputStream . |
java.io.OutputStream |
asOutputStream()
Expose this buffer's data as an
OutputStream . |
int |
capacity()
Return the number of bytes that this buffer can contain.
|
DataBuffer |
capacity(int newCapacity)
Set the number of bytes that this buffer can contain.
|
DataBuffer |
ensureCapacity(int capacity)
Ensure that the current buffer has enough
DataBuffer.writableByteCount()
to write the amount of data given as an argument. |
DataBufferFactory |
factory()
Return the
DataBufferFactory that created this buffer. |
byte |
getByte(int index)
Read a single byte at the given index from this data buffer.
|
int |
indexOf(java.util.function.IntPredicate predicate,
int fromIndex)
Return the index of the first byte in this buffer that matches
the given predicate.
|
boolean |
isAllocated()
Return
true if this buffer is allocated;
false if it has been deallocated. |
int |
lastIndexOf(java.util.function.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.
|
DataBuffer |
read(byte[] destination)
Read this buffer's data into the specified destination, starting at the current
reading position of this buffer.
|
DataBuffer |
read(byte[] destination,
int offset,
int length)
Read at most
length 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.
|
DataBuffer |
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.
|
DataBuffer |
slice(int index,
int length)
Create a new
DataBuffer whose contents is a shared subsequence of this
data buffer's content. |
int |
writableByteCount()
Return the number of bytes that can be written to this data buffer.
|
DataBuffer |
write(byte b)
Write a single byte into this buffer at the current writing position.
|
DataBuffer |
write(byte[] source)
Write the given source into this buffer, starting at the current writing position
of this buffer.
|
DataBuffer |
write(byte[] source,
int offset,
int length)
Write at most
length bytes of the given source into this buffer, starting
at the current writing position of this buffer. |
DataBuffer |
write(java.nio.ByteBuffer... byteBuffers)
Write one or more
ByteBuffer to this buffer, starting at the current
writing position. |
DataBuffer |
write(java.lang.CharSequence charSequence,
java.nio.charset.Charset charset)
Write the given
CharSequence using the given Charset ,
starting at the current writing position. |
DataBuffer |
write(DataBuffer... buffers)
Write one or more
DataBuffer s to this buffer, starting at the current
writing position. |
int |
writePosition()
Return the position to which this buffer will write.
|
DataBuffer |
writePosition(int writePosition)
Set the position to which this buffer will write.
|
private final DataBuffer dataBuffer
private final PooledByteBuffer pooledByteBuffer
public UndertowDataBuffer(DataBuffer dataBuffer, PooledByteBuffer pooledByteBuffer)
public boolean isAllocated()
PooledDataBuffer
true
if this buffer is allocated;
false
if it has been deallocated.isAllocated
in interface PooledDataBuffer
public PooledDataBuffer retain()
PooledDataBuffer
retain
in interface PooledDataBuffer
public boolean release()
PooledDataBuffer
release
in interface PooledDataBuffer
true
if the buffer was deallocated;
false
otherwisepublic DataBufferFactory factory()
DataBuffer
DataBufferFactory
that created this buffer.factory
in interface DataBuffer
public int indexOf(java.util.function.IntPredicate predicate, int fromIndex)
DataBuffer
indexOf
in interface DataBuffer
predicate
- the predicate to matchfromIndex
- the index to start the search frompredicate
;
or -1
if none matchpublic int lastIndexOf(java.util.function.IntPredicate predicate, int fromIndex)
DataBuffer
lastIndexOf
in interface DataBuffer
predicate
- the predicate to matchfromIndex
- the index to start the search frompredicate
;
or -1
if none matchpublic int readableByteCount()
DataBuffer
readableByteCount
in interface DataBuffer
public int writableByteCount()
DataBuffer
writableByteCount
in interface DataBuffer
public int readPosition()
DataBuffer
readPosition
in interface DataBuffer
public DataBuffer readPosition(int readPosition)
DataBuffer
readPosition
in interface DataBuffer
readPosition
- the new read positionpublic int writePosition()
DataBuffer
writePosition
in interface DataBuffer
public DataBuffer writePosition(int writePosition)
DataBuffer
writePosition
in interface DataBuffer
writePosition
- the new write positionpublic int capacity()
DataBuffer
capacity
in interface DataBuffer
public DataBuffer capacity(int newCapacity)
DataBuffer
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
in interface DataBuffer
newCapacity
- the new capacitypublic DataBuffer ensureCapacity(int capacity)
DataBuffer
DataBuffer.writableByteCount()
to write the amount of data given as an argument. If not, the missing
capacity will be added to the buffer.ensureCapacity
in interface DataBuffer
capacity
- the writable capacity to check forpublic byte getByte(int index)
DataBuffer
getByte
in interface DataBuffer
index
- the index at which the byte will be readpublic byte read()
DataBuffer
read
in interface DataBuffer
public DataBuffer read(byte[] destination)
DataBuffer
read
in interface DataBuffer
destination
- the array into which the bytes are to be writtenpublic DataBuffer read(byte[] destination, int offset, int length)
DataBuffer
length
bytes of this buffer into the specified destination,
starting at the current reading position of this buffer.read
in interface DataBuffer
destination
- the array into which the bytes are to be writtenoffset
- the index within destination
of the first byte to be writtenlength
- the maximum number of bytes to be written in destination
public DataBuffer write(byte b)
DataBuffer
write
in interface DataBuffer
b
- the byte to be writtenpublic DataBuffer write(byte[] source)
DataBuffer
write
in interface DataBuffer
source
- the bytes to be written into this bufferpublic DataBuffer write(byte[] source, int offset, int length)
DataBuffer
length
bytes of the given source into this buffer, starting
at the current writing position of this buffer.write
in interface DataBuffer
source
- the bytes to be written into this bufferoffset
- the index within source
to start writing fromlength
- the maximum number of bytes to be written from source
public DataBuffer write(DataBuffer... buffers)
DataBuffer
DataBuffer
s to this buffer, starting at the current
writing position. It is the responsibility of the caller to
release the given data buffers.write
in interface DataBuffer
buffers
- the byte buffers to write into this bufferpublic DataBuffer write(java.nio.ByteBuffer... byteBuffers)
DataBuffer
ByteBuffer
to this buffer, starting at the current
writing position.write
in interface DataBuffer
byteBuffers
- the byte buffers to write into this bufferpublic DataBuffer write(java.lang.CharSequence charSequence, java.nio.charset.Charset charset)
DataBuffer
CharSequence
using the given Charset
,
starting at the current writing position.write
in interface DataBuffer
charSequence
- the char sequence to write into this buffercharset
- the charset to encode the char sequence withpublic DataBuffer slice(int index, int length)
DataBuffer
DataBuffer
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
in interface DataBuffer
index
- the index at which to start the slicelength
- the length of the slicepublic java.nio.ByteBuffer asByteBuffer()
DataBuffer
ByteBuffer
. Data between this
DataBuffer
and the returned ByteBuffer
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
in interface DataBuffer
public java.nio.ByteBuffer asByteBuffer(int index, int length)
DataBuffer
ByteBuffer
. Data between
this DataBuffer
and the returned ByteBuffer
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
in interface DataBuffer
index
- the index at which to start the byte bufferlength
- the length of the returned byte bufferpublic java.io.InputStream asInputStream()
DataBuffer
InputStream
. 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
in interface DataBuffer
DataBuffer.asInputStream(boolean)
public java.io.InputStream asInputStream(boolean releaseOnClose)
DataBuffer
InputStream
. Both data and read position are
shared between the returned stream and this data buffer.asInputStream
in interface DataBuffer
releaseOnClose
- whether the underlying buffer will be
released when the input stream is
closed.public java.io.OutputStream asOutputStream()
DataBuffer
OutputStream
. Both data and write position are
shared between the returned stream and this data buffer.asOutputStream
in interface DataBuffer