public class Buffers
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
bufferCopy(java.nio.ByteBuffer src,
int srcPos,
java.nio.ByteBuffer dst,
int dstPos,
int length)
Perform a copy of the specified buffer range, analogously to
System#arraycopy. |
static java.nio.ByteBuffer |
castToByteBuffer(java.nio.IntBuffer buffer)
Convert the given input buffer into a direct byte buffer with native
byte order, by casting all elements to
byte. |
static java.nio.ByteBuffer |
castToShortByteBuffer(java.nio.IntBuffer buffer)
Convert the given input buffer into a direct byte buffer with native
byte order that contains the elements of the given input buffer,
casted to
short. |
static java.nio.ByteBuffer |
concat(java.util.Collection<? extends java.nio.ByteBuffer> byteBuffers)
Create a direct byte buffer with native byte order whose contents is
a concatenation of the given byte buffers.
|
static java.nio.ByteBuffer |
copyOf(java.nio.ByteBuffer buffer,
int newCapacity)
Creates a copy of the given buffer, as a direct buffer with the
same byte order, and the given capacity.
|
static java.nio.ByteBuffer |
create(byte[] data)
Creates a new, direct byte buffer that contains the given data,
with little-endian byte order
|
static java.nio.ByteBuffer |
create(byte[] data,
int offset,
int length)
Creates a new, direct byte buffer that contains the specified range
of the given data, with little-endian byte order
|
static java.nio.ByteBuffer |
create(int size)
Create a new direct byte buffer with the given size, and little-endian
byte order.
|
static java.nio.ByteBuffer |
createByteBufferFrom(java.nio.FloatBuffer buffer)
Create a new direct byte buffer with native byte order that has the
same contents as the given float buffer.
|
static java.nio.ByteBuffer |
createByteBufferFrom(java.nio.IntBuffer buffer)
Create a new direct byte buffer with native byte order that has the
same contents as the given int buffer.
|
static java.nio.ByteBuffer |
createByteBufferFrom(java.nio.ShortBuffer buffer)
Create a new direct byte buffer with native byte order that has the
same contents as the given short buffer.
|
static java.io.InputStream |
createByteBufferInputStream(java.nio.ByteBuffer byteBuffer)
Create an input stream from the given byte buffer, starting at its
current position, up to its current limit.
|
static java.nio.ByteBuffer |
createSlice(java.nio.ByteBuffer byteBuffer)
Create a slice of the given byte buffer, using its current position
and limit.
|
static java.nio.ByteBuffer |
createSlice(java.nio.ByteBuffer byteBuffer,
int position,
int length)
Create a slice of the given byte buffer, in the specified range.
|
static java.lang.String |
readAsString(java.nio.ByteBuffer byteBuffer)
Returns the contents of the given byte buffer as a string, using
the platform's default charset, or
null if the given
buffer is null. |
public static java.lang.String readAsString(java.nio.ByteBuffer byteBuffer)
null if the given
buffer is null. The position and limit of the given
buffer will be unaffected by this call.byteBuffer - The byte bufferpublic static java.nio.ByteBuffer createSlice(java.nio.ByteBuffer byteBuffer)
null, then
null will be returned.byteBuffer - The byte bufferpublic static java.nio.ByteBuffer createSlice(java.nio.ByteBuffer byteBuffer,
int position,
int length)
null, then
null will be returned.byteBuffer - The byte bufferposition - The position where the slice should startlength - The length of the slicejava.lang.IllegalArgumentException - If the range that is specified
by the position and length are not valid for the given bufferpublic static java.nio.ByteBuffer create(byte[] data)
data - The datapublic static java.nio.ByteBuffer create(byte[] data,
int offset,
int length)
data - The dataoffset - The offset in the data arraylength - The length of the rangepublic static java.nio.ByteBuffer create(int size)
size - The size of the bufferjava.lang.IllegalArgumentException - If the given size is negativepublic static java.io.InputStream createByteBufferInputStream(java.nio.ByteBuffer byteBuffer)
byteBuffer - The bufferpublic static java.nio.ByteBuffer concat(java.util.Collection<? extends java.nio.ByteBuffer> byteBuffers)
null or empty, then a 0-byte buffer will be created.
The given collection may not contain null elements.byteBuffers - The input byte bufferspublic static java.nio.ByteBuffer createByteBufferFrom(java.nio.FloatBuffer buffer)
buffer - The input bufferpublic static java.nio.ByteBuffer createByteBufferFrom(java.nio.IntBuffer buffer)
buffer - The input bufferpublic static java.nio.ByteBuffer createByteBufferFrom(java.nio.ShortBuffer buffer)
buffer - The input bufferpublic static java.nio.ByteBuffer castToByteBuffer(java.nio.IntBuffer buffer)
byte.buffer - The input bufferpublic static java.nio.ByteBuffer castToShortByteBuffer(java.nio.IntBuffer buffer)
short.buffer - The input bufferpublic static java.nio.ByteBuffer copyOf(java.nio.ByteBuffer buffer,
int newCapacity)
buffer - The input buffernewCapacity - The new capacitypublic static void bufferCopy(java.nio.ByteBuffer src,
int srcPos,
java.nio.ByteBuffer dst,
int dstPos,
int length)
System#arraycopy.src - The source buffersrcPos - The source positiondst - The destination bufferdstPos - The destination positionlength - The lengthjava.lang.IndexOutOfBoundsException - If the indices are invalid.Copyright © 2022. All Rights Reserved.