Java Utililty Methods ByteBuffer Set

List of utility methods to do ByteBuffer Set

Description

The list of methods to do ByteBuffer Set are organized into topic(s).

Method

byte[]redByteArray(ByteBuffer buffer, int offset, int length)
red Byte Array
byte[] dst = new byte[length];
for (int i = 0; i < length; i++) {
    dst[i] = buffer.get(offset + i);
return dst;
byteredInteger1(ByteBuffer buffer, int _offset)
red Integer
return buffer.get(_offset);
StringredString(ByteBuffer buffer, int offset, Charset charset)
red String
ByteArrayOutputStream out = new ByteArrayOutputStream();
for (int i = offset; i < buffer.limit(); i++) {
    if (((char) buffer.get(i)) == '\0') {
        break;
    out.write(new byte[] { buffer.get(i) });
return new String(out.toByteArray(), charset);
...
voidreleaseTemporaryDirectBuffer(ByteBuffer buf)
release Temporary Direct Buffer
if (buf == null)
    return;
for (int i = 0; i < TEMP_BUF_POOL_SIZE; i++) {
    SoftReference<ByteBuffer> ref = (bufferPool[i].get());
    if ((ref == null) || (ref.get() == null)) {
        bufferPool[i].set(new SoftReference<>(buf));
        return;
for (int i = 0; i < TEMP_BUF_POOL_SIZE; i++) {
    SoftReference ref = (bufferPool[i].get());
    ByteBuffer inCacheBuf = (ByteBuffer) ref.get();
    if ((inCacheBuf == null) || (buf.capacity() > inCacheBuf.capacity())) {
        bufferPool[i].set(new SoftReference<>(buf));
        return;
voidreset(int offset, ByteBuffer b)
reset
b.position(offset);
b.mark(); 
voidresetBit(ByteBuffer in, int pos)
Sets the bit in given input to zero Sets the pos bit in input to zero
in.put(pos >> 3, (byte) (in.get(pos >> 3) & ~(1 << (pos % NBITS_PER_BYTE))));
voidset0byte(MappedByteBuffer mem, byte value)
setbyte
mem.put(0, value);
mem.force();
voidset24BitInt(ByteBuffer buffer, int value)
Places the given value into the given buffer as a 3 byte integer.
if (buffer.order() == ByteOrder.BIG_ENDIAN) {
    buffer.put((byte) (value >> 16));
    buffer.put((byte) ((value >>> 8) & 0xFF));
    buffer.put((byte) (value & 0xFF));
} else {
    buffer.put((byte) (value & 0xFF));
    buffer.put((byte) ((value >>> 8) & 0xFF));
    buffer.put((byte) (value >> 16));
...
voidsetBatch(ByteBuffer bb, long batchId)
set Batch
bb.putLong(batchPos, batchId);
voidsetByteOrder(ByteBuffer buffer)
set Byte Order
buffer.order(ByteOrder.LITTLE_ENDIAN);