public final class Buffers
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.nio.ByteBuffer |
EMPTY_BYTE_BUFFER
The empty byte buffer.
|
static Pooled<java.nio.ByteBuffer> |
EMPTY_POOLED_BYTE_BUFFER
The empty pooled byte buffer.
|
Modifier and Type | Method and Description |
---|---|
static void |
addRandom(java.nio.ByteBuffer target)
Add a random amount of random data to the target buffer using the thread-local RNG.
|
static void |
addRandom(java.nio.ByteBuffer target,
int count)
Add
count bytes of random data to the target buffer using the thread-local RNG. |
static void |
addRandom(java.nio.ByteBuffer target,
java.util.Random random)
Add a random amount of random data to the target buffer.
|
static void |
addRandom(java.nio.ByteBuffer target,
java.util.Random random,
int count)
Add
count bytes of random data to the target buffer. |
static <B extends java.nio.Buffer> |
allocatedBufferPool(BufferAllocator<B> allocator,
int size)
A buffer pool which allocates a new buffer on every allocate request, and discards buffers on free.
|
static void |
assertWritable(java.nio.Buffer... buffers)
Assert the writability of the given buffers.
|
static void |
assertWritable(java.nio.Buffer[] buffers,
int offs,
int len)
Assert the writability of the given buffers.
|
static <T extends java.nio.Buffer> |
clear(T buffer)
Clear a buffer.
|
static int |
copy(java.nio.ByteBuffer[] destinations,
int offset,
int length,
java.nio.ByteBuffer source)
Copy as many bytes as possible from
sources into destinations in a "scatter" fashion. |
static long |
copy(java.nio.ByteBuffer[] destinations,
int destOffset,
int destLength,
java.nio.ByteBuffer[] sources,
int srcOffset,
int srcLength)
Copy as many bytes as possible from
sources into destinations by a combined "scatter"/"gather" operation. |
static int |
copy(java.nio.ByteBuffer destination,
java.nio.ByteBuffer source)
Copy as many bytes as possible from
source into destination . |
static int |
copy(java.nio.ByteBuffer destination,
java.nio.ByteBuffer[] sources,
int offset,
int length)
Copy as many bytes as possible from
sources into destination in a "gather" fashion. |
static java.nio.ByteBuffer |
copy(java.nio.ByteBuffer buffer,
int count,
BufferAllocator<java.nio.ByteBuffer> allocator)
Copy a portion of the buffer into a newly allocated buffer.
|
static int |
copy(int count,
java.nio.ByteBuffer[] destinations,
int offset,
int length,
java.nio.ByteBuffer source)
Copy at most
count bytes from sources into destinations in a "scatter" fashion. |
static int |
copy(int count,
java.nio.ByteBuffer destination,
java.nio.ByteBuffer source)
Copy at most
count bytes from source into destination . |
static int |
copy(int count,
java.nio.ByteBuffer destination,
java.nio.ByteBuffer[] sources,
int offset,
int length)
Copy at most
count bytes from sources into destination in a "gather" fashion. |
static long |
copy(long count,
java.nio.ByteBuffer[] destinations,
int destOffset,
int destLength,
java.nio.ByteBuffer[] sources,
int srcOffset,
int srcLength)
Copy at most
count bytes from sources into destinations by a combined "scatter"/"gather" operation. |
static java.lang.Object |
createDumper(java.nio.ByteBuffer buffer,
int indent,
int columns)
Create an object that returns the dumped form of the given byte buffer when its
toString() method is called. |
static java.lang.Object |
createDumper(java.nio.CharBuffer buffer,
int indent,
int columns)
Create an object that returns the dumped form of the given character buffer when its
toString() method is called. |
static java.lang.String |
debugString(java.nio.ByteBuffer buffer)
Get a debug-friendly description of the buffer.
|
static java.lang.String |
debugString(java.nio.ByteBuffer[] buffers,
int offs,
int len)
Get a debug-friendly description of the buffer.
|
static void |
dump(java.nio.ByteBuffer buffer,
java.lang.Appendable dest,
int indent,
int columns)
Dump a byte buffer to the given target.
|
static void |
dump(java.nio.CharBuffer buffer,
java.lang.Appendable dest,
int indent,
int columns)
Dump a character buffer to the given target.
|
static Pooled<java.nio.ByteBuffer> |
emptyPooledByteBuffer()
Create a "pooled" empty buffer.
|
static void |
emptyToStream(java.io.OutputStream target,
java.nio.ByteBuffer source)
Empty a buffer to an output stream.
|
static java.nio.ByteBuffer |
fill(java.nio.ByteBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value.
|
static java.nio.CharBuffer |
fill(java.nio.CharBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value.
|
static java.nio.IntBuffer |
fill(java.nio.IntBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value.
|
static java.nio.LongBuffer |
fill(java.nio.LongBuffer buffer,
long value,
int count)
Fill a buffer with a repeated value.
|
static java.nio.ShortBuffer |
fill(java.nio.ShortBuffer buffer,
int value,
int count)
Fill a buffer with a repeated value.
|
static int |
fillFromStream(java.nio.ByteBuffer target,
java.io.InputStream source)
Fill a buffer from an input stream.
|
static <T extends java.nio.Buffer> |
flip(T buffer)
Flip a buffer.
|
static java.lang.String |
getModifiedUtf8(java.nio.ByteBuffer src)
Get a modified UTF-8 string from the remainder of the buffer.
|
static java.lang.String |
getModifiedUtf8Z(java.nio.ByteBuffer src)
Get a 0-terminated string from the byte buffer, decoding it using "modified UTF-8" encoding.
|
static Pooled<java.nio.ByteBuffer> |
globalPooledWrapper(java.nio.ByteBuffer buffer)
Create a pooled wrapper around a buffer that was allocated via
ByteBufferPool . |
static boolean |
hasRemaining(java.nio.Buffer[] buffers)
Determine whether any of the buffers has remaining data.
|
static boolean |
hasRemaining(java.nio.Buffer[] buffers,
int offs,
int len)
Determine whether any of the buffers has remaining data.
|
static boolean |
isDirect(java.nio.Buffer... buffers)
Determine whether the given buffers list is comprised solely of direct buffers or solely of heap buffers.
|
static boolean |
isDirect(java.nio.Buffer[] buffers,
int offset,
int length)
Determine whether the given buffers list is comprised solely of direct buffers or solely of heap buffers.
|
static boolean |
isSecureBufferPool(Pool<?> pool)
Determine whether the given pool is a secure pool.
|
static <T extends java.nio.Buffer> |
limit(T buffer,
int limit)
Set the buffer limit.
|
static <T extends java.nio.Buffer> |
mark(T buffer)
Set the buffer mark.
|
static <B extends java.nio.Buffer> |
pooledWrapper(B buffer)
Create a pooled wrapper around a buffer.
|
static <T extends java.nio.Buffer> |
position(T buffer,
int position)
Set the buffer position.
|
static java.nio.ByteBuffer |
putModifiedUtf8(java.nio.ByteBuffer dest,
java.lang.String orig)
Put the string into the byte buffer, encoding it using "modified UTF-8" encoding.
|
static void |
readAscii(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read the remainder of a buffer as ASCII text, appending the results to the given string
builder.
|
static void |
readAscii(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement)
Read the remainder of a buffer as ASCII text, appending the results to the given string
builder.
|
static void |
readAscii(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
int limit,
char replacement)
Read the remainder of a buffer as ASCII text, up to a certain limit, appending the results to the given string
builder.
|
static boolean |
readAsciiLine(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read a single line of ASCII text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readAsciiLine(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement)
Read a single line of ASCII text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readAsciiLine(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement,
char delimiter)
Read a single line of ASCII text from a byte buffer, appending the results to the given string
builder, using the given delimiter character instead of
EOL . |
static boolean |
readAsciiZ(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read an ASCIIZ (
NUL -terminated) string from a byte buffer, appending the results to the given string
builder. |
static boolean |
readAsciiZ(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement)
Read an ASCIIZ (
NUL -terminated) string from a byte buffer, appending the results to the given string
builder. |
static void |
readLatin1(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read the remainder of a buffer as Latin-1 text, appending the results to the given string
builder.
|
static boolean |
readLatin1Line(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read a single line of Latin-1 text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readLatin1Line(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char delimiter)
Read a single line of Latin-1 text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readLatin1Z(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read a
NUL -terminated Latin-1 string from a byte buffer, appending the results to the given string
builder. |
static boolean |
readLine(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
java.nio.charset.CharsetDecoder decoder)
Read a single line of text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readLine(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
java.nio.charset.CharsetDecoder decoder,
char delimiter)
Read a single line of text from a byte buffer, appending the results to the given string
builder.
|
static boolean |
readModifiedUtf8Line(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read a single line of
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
static boolean |
readModifiedUtf8Line(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement)
Read a single line of
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
static boolean |
readModifiedUtf8Line(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement,
char delimiter)
Read a single line of
modified UTF-8 text from a byte buffer, appending the results to the given string
builder. |
static boolean |
readModifiedUtf8Z(java.nio.ByteBuffer src,
java.lang.StringBuilder builder)
Read a
NUL -terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. |
static boolean |
readModifiedUtf8Z(java.nio.ByteBuffer src,
java.lang.StringBuilder builder,
char replacement)
Read a
NUL -terminated modified UTF-8 string from a byte buffer, appending the results to the given string
builder. |
static long |
remaining(java.nio.Buffer[] buffers)
Get the total remaining size of all the given buffers.
|
static long |
remaining(java.nio.Buffer[] buffers,
int offs,
int len)
Get the total remaining size of all the given buffers.
|
static <T extends java.nio.Buffer> |
reset(T buffer)
Reset the buffer.
|
static <T extends java.nio.Buffer> |
rewind(T buffer)
Rewind the buffer.
|
static Pool<java.nio.ByteBuffer> |
secureBufferPool(Pool<java.nio.ByteBuffer> delegate)
A byte buffer pool which zeroes the content of the buffer before re-pooling it.
|
static <T extends java.nio.Buffer> |
skip(T buffer,
int cnt)
Advance a buffer's position relative to its current position.
|
static java.nio.ByteBuffer |
slice(java.nio.ByteBuffer buffer,
int sliceSize)
Slice the buffer.
|
static java.nio.CharBuffer |
slice(java.nio.CharBuffer buffer,
int sliceSize)
Slice the buffer.
|
static java.nio.IntBuffer |
slice(java.nio.IntBuffer buffer,
int sliceSize)
Slice the buffer.
|
static java.nio.LongBuffer |
slice(java.nio.LongBuffer buffer,
int sliceSize)
Slice the buffer.
|
static java.nio.ShortBuffer |
slice(java.nio.ShortBuffer buffer,
int sliceSize)
Slice the buffer.
|
static BufferAllocator<java.nio.ByteBuffer> |
sliceAllocator(java.nio.ByteBuffer buffer)
A buffer allocator which allocates slices off of the given buffer.
|
static byte[] |
take(java.nio.ByteBuffer buffer)
Take all of the remaining bytes from the buffer and return them in an array.
|
static byte[] |
take(java.nio.ByteBuffer[] buffers,
int offs,
int len)
Take all of the remaining bytes from the buffers and return them in an array.
|
static byte[] |
take(java.nio.ByteBuffer buffer,
int cnt)
Take a certain number of bytes from the buffer and return them in an array.
|
static char[] |
take(java.nio.CharBuffer buffer)
Take all of the remaining chars from the buffer and return them in an array.
|
static char[] |
take(java.nio.CharBuffer buffer,
int cnt)
Take a certain number of chars from the buffer and return them in an array.
|
static int[] |
take(java.nio.IntBuffer buffer)
Take all of the remaining ints from the buffer and return them in an array.
|
static int[] |
take(java.nio.IntBuffer buffer,
int cnt)
Take a certain number of ints from the buffer and return them in an array.
|
static long[] |
take(java.nio.LongBuffer buffer)
Take all of the remaining longs from the buffer and return them in an array.
|
static long[] |
take(java.nio.LongBuffer buffer,
int cnt)
Take a certain number of longs from the buffer and return them in an array.
|
static short[] |
take(java.nio.ShortBuffer buffer)
Take all of the remaining shorts from the buffer and return them in an array.
|
static short[] |
take(java.nio.ShortBuffer buffer,
int cnt)
Take a certain number of shorts from the buffer and return them in an array.
|
static long |
trySkip(java.nio.Buffer[] buffers,
int offs,
int len,
long cnt)
Attempt to advance a series of buffers' overall position relative to its current position.
|
static int |
trySkip(java.nio.Buffer buffer,
int cnt)
Attempt to advance a buffer's position relative to its current position.
|
static <T extends java.nio.Buffer> |
unget(T buffer,
int cnt)
Rewind a buffer's position relative to its current position.
|
static void |
zero(java.nio.ByteBuffer buffer)
Zero a buffer.
|
static void |
zero(java.nio.CharBuffer buffer)
Zero a buffer.
|
public static final java.nio.ByteBuffer EMPTY_BYTE_BUFFER
public static final Pooled<java.nio.ByteBuffer> EMPTY_POOLED_BYTE_BUFFER
public static <T extends java.nio.Buffer> T flip(T buffer)
T
- the buffer typebuffer
- the buffer to flipBuffer.flip()
public static <T extends java.nio.Buffer> T clear(T buffer)
T
- the buffer typebuffer
- the buffer to clearBuffer.clear()
public static <T extends java.nio.Buffer> T limit(T buffer, int limit)
T
- the buffer typebuffer
- the buffer to setlimit
- the new limitBuffer.limit(int)
public static <T extends java.nio.Buffer> T mark(T buffer)
T
- the buffer typebuffer
- the buffer to markBuffer.mark()
public static <T extends java.nio.Buffer> T position(T buffer, int position)
T
- the buffer typebuffer
- the buffer to setposition
- the new positionBuffer.position(int)
public static <T extends java.nio.Buffer> T reset(T buffer)
T
- the buffer typebuffer
- the buffer to resetBuffer.reset()
public static <T extends java.nio.Buffer> T rewind(T buffer)
T
- the buffer typebuffer
- the buffer to rewindBuffer.rewind()
public static java.nio.ByteBuffer slice(java.nio.ByteBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceByteBuffer.slice()
public static java.nio.ByteBuffer copy(java.nio.ByteBuffer buffer, int count, BufferAllocator<java.nio.ByteBuffer> allocator)
buffer
- the buffer to slicecount
- the size of the copyallocator
- the buffer allocator to usepublic static int copy(java.nio.ByteBuffer destination, java.nio.ByteBuffer source)
source
into destination
.destination
- the destination buffersource
- the source bufferpublic static int copy(java.nio.ByteBuffer[] destinations, int offset, int length, java.nio.ByteBuffer source)
sources
into destinations
in a "scatter" fashion.destinations
- the destination buffersoffset
- the offset into the destination buffers arraylength
- the number of buffers to updatesource
- the source bufferpublic static int copy(java.nio.ByteBuffer destination, java.nio.ByteBuffer[] sources, int offset, int length)
sources
into destination
in a "gather" fashion.destination
- the destination buffersources
- the source buffersoffset
- the offset into the source buffers arraylength
- the number of buffers to read frompublic static long copy(java.nio.ByteBuffer[] destinations, int destOffset, int destLength, java.nio.ByteBuffer[] sources, int srcOffset, int srcLength)
sources
into destinations
by a combined "scatter"/"gather" operation.destinations
- the destination buffersdestOffset
- the offset into the destination buffers arraydestLength
- the number of buffers to write tosources
- the source bufferssrcOffset
- the offset into the source buffers arraysrcLength
- the number of buffers to read frompublic static int copy(int count, java.nio.ByteBuffer destination, java.nio.ByteBuffer source)
count
bytes from source
into destination
.count
- the maximum number of bytes to copydestination
- the destination buffersource
- the source bufferpublic static int copy(int count, java.nio.ByteBuffer[] destinations, int offset, int length, java.nio.ByteBuffer source)
count
bytes from sources
into destinations
in a "scatter" fashion.count
- the maximum number of bytes to copydestinations
- the destination buffersoffset
- the offset into the destination buffers arraylength
- the number of buffers to updatesource
- the source bufferpublic static int copy(int count, java.nio.ByteBuffer destination, java.nio.ByteBuffer[] sources, int offset, int length)
count
bytes from sources
into destination
in a "gather" fashion.count
- the maximum number of bytes to copydestination
- the destination buffersources
- the source buffersoffset
- the offset into the source buffers arraylength
- the number of buffers to read frompublic static long copy(long count, java.nio.ByteBuffer[] destinations, int destOffset, int destLength, java.nio.ByteBuffer[] sources, int srcOffset, int srcLength)
count
bytes from sources
into destinations
by a combined "scatter"/"gather" operation.count
- the maximum number of bytes to copydestinations
- the destination buffersdestOffset
- the offset into the destination buffers arraydestLength
- the number of buffers to write tosources
- the source bufferssrcOffset
- the offset into the source buffers arraysrcLength
- the number of buffers to read frompublic static java.nio.ByteBuffer fill(java.nio.ByteBuffer buffer, int value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of bytes to fillpublic static java.nio.CharBuffer slice(java.nio.CharBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceCharBuffer.slice()
public static java.nio.CharBuffer fill(java.nio.CharBuffer buffer, int value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of chars to fillpublic static java.nio.ShortBuffer slice(java.nio.ShortBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceShortBuffer.slice()
public static java.nio.ShortBuffer fill(java.nio.ShortBuffer buffer, int value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of shorts to fillpublic static java.nio.IntBuffer slice(java.nio.IntBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceIntBuffer.slice()
public static java.nio.IntBuffer fill(java.nio.IntBuffer buffer, int value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of ints to fillpublic static java.nio.LongBuffer slice(java.nio.LongBuffer buffer, int sliceSize)
buffer
- the buffer to slicesliceSize
- the size of the sliceLongBuffer.slice()
public static java.nio.LongBuffer fill(java.nio.LongBuffer buffer, long value, int count)
buffer
- the buffer to fillvalue
- the value to fillcount
- the number of longs to fillpublic static <T extends java.nio.Buffer> T skip(T buffer, int cnt) throws java.nio.BufferUnderflowException
T
- the buffer typebuffer
- the buffer to setcnt
- the distance to skipjava.nio.BufferUnderflowException
- if there are fewer than cnt
bytes remainingBuffer.position(int)
public static int trySkip(java.nio.Buffer buffer, int cnt)
buffer
- the buffer to setcnt
- the distance to skipBuffer.position(int)
public static long trySkip(java.nio.Buffer[] buffers, int offs, int len, long cnt)
buffers
- the buffers to setoffs
- the offset into the buffers arraylen
- the number of buffers to considercnt
- the distance to skipBuffer.position(int)
public static <T extends java.nio.Buffer> T unget(T buffer, int cnt)
T
- the buffer typebuffer
- the buffer to setcnt
- the distance to skip backwardsBuffer.position(int)
public static byte[] take(java.nio.ByteBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of bytes to takepublic static char[] take(java.nio.CharBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of chars to takepublic static short[] take(java.nio.ShortBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of shorts to takepublic static int[] take(java.nio.IntBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of ints to takepublic static long[] take(java.nio.LongBuffer buffer, int cnt)
buffer
- the buffer to readcnt
- the number of longs to takepublic static byte[] take(java.nio.ByteBuffer buffer)
buffer
- the buffer to readpublic static byte[] take(java.nio.ByteBuffer[] buffers, int offs, int len)
buffers
- the buffer to readoffs
- the offset into the arraylen
- the number of bufferspublic static char[] take(java.nio.CharBuffer buffer)
buffer
- the buffer to readpublic static short[] take(java.nio.ShortBuffer buffer)
buffer
- the buffer to readpublic static int[] take(java.nio.IntBuffer buffer)
buffer
- the buffer to readpublic static long[] take(java.nio.LongBuffer buffer)
buffer
- the buffer to readpublic static java.lang.Object createDumper(java.nio.ByteBuffer buffer, int indent, int columns)
toString()
method is called.
Useful for logging byte buffers; if the toString()
method is never called, the process of dumping the
buffer is never performed.buffer
- the bufferindent
- the indentation to usecolumns
- the number of 8-byte columnspublic static void dump(java.nio.ByteBuffer buffer, java.lang.Appendable dest, int indent, int columns) throws java.io.IOException
buffer
- the bufferdest
- the targetindent
- the indentation to usecolumns
- the number of 8-byte columnsjava.io.IOException
- if an error occurs during appendpublic static java.lang.Object createDumper(java.nio.CharBuffer buffer, int indent, int columns)
toString()
method is called.
Useful for logging character buffers; if the toString()
method is never called, the process of dumping the
buffer is never performed.buffer
- the bufferindent
- the indentation to usecolumns
- the number of 8-byte columnspublic static void dump(java.nio.CharBuffer buffer, java.lang.Appendable dest, int indent, int columns) throws java.io.IOException
buffer
- the bufferdest
- the targetindent
- the indentation to usecolumns
- the number of 8-byte columnsjava.io.IOException
- if an error occurs during appendpublic static boolean hasRemaining(java.nio.Buffer[] buffers, int offs, int len)
buffers
- the buffersoffs
- the offset into the buffers arraylen
- the number of buffers to checktrue
if any of the selected buffers has remaining datapublic static boolean hasRemaining(java.nio.Buffer[] buffers)
buffers
- the bufferstrue
if any of the selected buffers has remaining datapublic static long remaining(java.nio.Buffer[] buffers, int offs, int len)
buffers
- the buffersoffs
- the offset into the buffers arraylen
- the number of buffers to checkpublic static long remaining(java.nio.Buffer[] buffers)
buffers
- the bufferspublic static java.nio.ByteBuffer putModifiedUtf8(java.nio.ByteBuffer dest, java.lang.String orig) throws java.nio.BufferOverflowException
dest
- the byte bufferorig
- the source bytesjava.nio.BufferOverflowException
- if there is not enough space in the buffer for the complete stringDataOutput.writeUTF(String)
public static java.lang.String getModifiedUtf8Z(java.nio.ByteBuffer src) throws java.nio.BufferUnderflowException
src
- the source bufferjava.nio.BufferUnderflowException
- if the end of the buffer was reached before encountering a 0
public static java.lang.String getModifiedUtf8(java.nio.ByteBuffer src) throws java.nio.BufferUnderflowException
src
- the bufferjava.nio.BufferUnderflowException
- if the buffer ends abruptly in the midst of a single characterpublic static boolean readAsciiZ(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
NUL
-terminated) string from a byte buffer, appending the results to the given string
builder. If no NUL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?'
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readAsciiZ(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement)
NUL
-terminated) string from a byte buffer, appending the results to the given string
builder. If no NUL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytestrue
if the entire string was read, false
if more data is neededpublic static boolean readAsciiLine(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?'
is written
to the string builder in its place. The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readAsciiLine(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement)
EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement
is written
to the string builder in its place. The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytestrue
if the entire string was read, false
if more data is neededpublic static boolean readAsciiLine(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement, char delimiter)
EOL
. If no delimiter character is encountered,
false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement
is written
to the string builder in its place. The delimiter character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytesdelimiter
- the character which marks the end of the linetrue
if the entire string was read, false
if more data is neededpublic static void readAscii(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
'?'
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderpublic static void readAscii(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement)
replacement
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytespublic static void readAscii(java.nio.ByteBuffer src, java.lang.StringBuilder builder, int limit, char replacement)
replacement
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderlimit
- the maximum number of characters to writereplacement
- the replacement character for invalid bytespublic static boolean readLatin1Z(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
NUL
-terminated Latin-1 string from a byte buffer, appending the results to the given string
builder. If no NUL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readLatin1Line(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readLatin1Line(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char delimiter)
false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. The delimiter character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderdelimiter
- the character which marks the end of the linetrue
if the entire string was read, false
if more data is neededpublic static void readLatin1(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
src
- the source bufferbuilder
- the destination builderpublic static boolean readModifiedUtf8Z(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
NUL
-terminated modified UTF-8
string from a byte buffer, appending the results to the given string
builder. If no NUL
byte is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte sequence is read, the character '?'
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readModifiedUtf8Z(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement)
NUL
-terminated modified UTF-8
string from a byte buffer, appending the results to the given string
builder. If no NUL
byte is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte sequence is read, the character designated by replacement
is written
to the string builder in its place.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character to usetrue
if the entire string was read, false
if more data is neededpublic static boolean readModifiedUtf8Line(java.nio.ByteBuffer src, java.lang.StringBuilder builder)
modified UTF-8
text from a byte buffer, appending the results to the given string
builder. If no EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character '?'
is written
to the string builder in its place. The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination buildertrue
if the entire string was read, false
if more data is neededpublic static boolean readModifiedUtf8Line(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement)
modified UTF-8
text from a byte buffer, appending the results to the given string
builder. If no EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement
is written
to the string builder in its place. The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytestrue
if the entire string was read, false
if more data is neededpublic static boolean readModifiedUtf8Line(java.nio.ByteBuffer src, java.lang.StringBuilder builder, char replacement, char delimiter)
modified UTF-8
text from a byte buffer, appending the results to the given string
builder. If no EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. If an invalid byte is read, the character designated by replacement
is written
to the string builder in its place. The delimiter character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderreplacement
- the replacement character for invalid bytesdelimiter
- the character which marks the end of the linetrue
if the entire string was read, false
if more data is neededpublic static boolean readLine(java.nio.ByteBuffer src, java.lang.StringBuilder builder, java.nio.charset.CharsetDecoder decoder)
EOL
character is encountered, false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. Invalid bytes are handled according to the policy specified by the decoder
instance.
Since this method decodes only one character at a time, it should not be expected to have the same performance
as the other optimized, character set-specific methods specified in this class.
The EOL
character will be included in the resultant string.src
- the source bufferbuilder
- the destination builderdecoder
- the decoder to usetrue
if the entire string was read, false
if more data is neededpublic static boolean readLine(java.nio.ByteBuffer src, java.lang.StringBuilder builder, java.nio.charset.CharsetDecoder decoder, char delimiter)
false
is returned, indicating that more data needs
to be acquired before the operation can be complete. On return, there may be data remaining
in the source buffer. Invalid bytes are handled according to the policy specified by the decoder
instance.
Since this method decodes only one character at a time, it should not be expected to have the same performance
as the other optimized, character set-specific methods specified in this class. The delimiter character will be
included in the resultant string.src
- the source bufferbuilder
- the destination builderdecoder
- the decoder to usedelimiter
- the character which marks the end of the linetrue
if the entire string was read, false
if more data is neededpublic static <B extends java.nio.Buffer> Pooled<B> pooledWrapper(B buffer)
B
- the buffer typebuffer
- the buffer to wrappublic static Pooled<java.nio.ByteBuffer> globalPooledWrapper(java.nio.ByteBuffer buffer)
ByteBufferPool
. The buffer is freed to the
global pool when freed.buffer
- the buffer to wrappublic static Pooled<java.nio.ByteBuffer> emptyPooledByteBuffer()
public static BufferAllocator<java.nio.ByteBuffer> sliceAllocator(java.nio.ByteBuffer buffer)
BufferUnderflowException
.buffer
- the source bufferpublic static <B extends java.nio.Buffer> Pool<B> allocatedBufferPool(BufferAllocator<B> allocator, int size)
B
- the buffer typeallocator
- the buffer allocatorsize
- the buffer sizepublic static Pool<java.nio.ByteBuffer> secureBufferPool(Pool<java.nio.ByteBuffer> delegate)
delegate
- the delegate poolpublic static boolean isSecureBufferPool(Pool<?> pool)
pool
- the pool to testtrue
if it is a secure pool instancepublic static void zero(java.nio.ByteBuffer buffer)
buffer
- the bufferpublic static void zero(java.nio.CharBuffer buffer)
buffer
- the bufferpublic static boolean isDirect(java.nio.Buffer... buffers) throws java.lang.IllegalArgumentException
buffers
- the bufferstrue
if all the buffers are direct, false
if they are all heap buffersjava.lang.IllegalArgumentException
- if both direct and heap buffers were found, or if a buffer is null
public static boolean isDirect(java.nio.Buffer[] buffers, int offset, int length)
buffers
- the bufferstrue
if all the buffers are direct, false
if they are all heap buffersjava.lang.IllegalArgumentException
- if both direct and heap buffers were found, or if a buffer is null
public static void assertWritable(java.nio.Buffer[] buffers, int offs, int len) throws java.nio.ReadOnlyBufferException
buffers
- the buffers arrayoffs
- the offset in the array to start searchinglen
- the number of buffers to checkjava.nio.ReadOnlyBufferException
- if any of the buffers are read-onlypublic static void assertWritable(java.nio.Buffer... buffers) throws java.nio.ReadOnlyBufferException
buffers
- the buffers arrayjava.nio.ReadOnlyBufferException
- if any of the buffers are read-onlypublic static void addRandom(java.nio.ByteBuffer target, java.util.Random random, int count)
count
bytes of random data to the target buffer.target
- the target bufferrandom
- the RNGcount
- the number of bytes to addpublic static void addRandom(java.nio.ByteBuffer target, int count)
count
bytes of random data to the target buffer using the thread-local RNG.target
- the target buffercount
- the number of bytes to addpublic static void addRandom(java.nio.ByteBuffer target, java.util.Random random)
target
- the target bufferrandom
- the RNGpublic static void addRandom(java.nio.ByteBuffer target)
target
- the target bufferpublic static int fillFromStream(java.nio.ByteBuffer target, java.io.InputStream source) throws java.io.IOException
target
- the target buffersource
- the source stream-1
if no bytes were moved due to end-of-streamjava.io.IOException
- if the stream read failspublic static java.lang.String debugString(java.nio.ByteBuffer buffer)
buffer
- the buffer to describepublic static java.lang.String debugString(java.nio.ByteBuffer[] buffers, int offs, int len)
buffers
- the buffers to describeoffs
- the offset into the arraylen
- the number of bufferspublic static void emptyToStream(java.io.OutputStream target, java.nio.ByteBuffer source) throws java.io.IOException
target
- the target streamsource
- the source bufferjava.io.IOException
- if the stream write failsCopyright © 2016 JBoss, a division of Red Hat, Inc.