Java Utililty Methods ByteBuffer Put

List of utility methods to do ByteBuffer Put

Description

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

Method

voidputByteBuffer(ByteBuffer source, ByteBuffer target)
Writes the contents of source to target without mutating source (so safe for multithreaded access to source) and without GC (unless source is a direct buffer).
if (source.hasArray()) {
    byte[] array = source.array();
    int arrayOffset = source.arrayOffset();
    target.put(array, arrayOffset + source.position(), source.remaining());
} else {
    target.put(source.duplicate());
voidputBytesUnescaped(ByteBuffer buffer, byte[] data)
put Bytes Unescaped
if (data.length > buffer.remaining()) {
    throw new IllegalArgumentException("Not enough room in the buffer for the data");
for (int ix = 0; ix < data.length; ix++) {
    byte b = data[ix];
    if (b == ESCAPE_CHARACTER) {
        buffer.put((byte) (data[++ix] ^ 0x20));
    } else {
...
voidputCharSequence(ByteBuffer buf, Charset charset, CharSequence value)
put Char Sequence
putCharSequence(buf, charset.newEncoder(), value);
voidputDecInt(ByteBuffer buffer, int n)
put Dec Int
if (n < 0) {
    buffer.put((byte) '-');
    if (n == Integer.MIN_VALUE) {
        buffer.put((byte) '2');
        n = 147483648;
    } else
        n = -n;
if (n < 10) {
    buffer.put(DIGIT[n]);
} else {
    boolean started = false;
    for (int decDivisor : decDivisors) {
        if (n < decDivisor) {
            if (started)
                buffer.put((byte) '0');
            continue;
        started = true;
        int d = n / decDivisor;
        buffer.put(DIGIT[d]);
        n = n - d * decDivisor;
voidputInt(ByteBuffer bb, long value)
Put an int into the byte buffer unsigned.
bb.putInt((int) (value & 0xffffffffL));
voidputInt(ByteBuffer buffer, int val, ByteOrder order)
Writes an int at the current position in the given buffer, using the given ByteOrder
int offset = buffer.position();
putInt(buffer, val, offset, order);
buffer.position(offset + 4);
voidputInt(final ByteBuffer buffer, int value)
put Int
buffer.put((byte) (value >> 24));
buffer.put((byte) (value >> 16));
buffer.put((byte) (value >> 8));
buffer.put((byte) value);
ByteBufferputInt(int i, ByteBuffer buffer)
Add the int to the buffer, extending the buffer if needed
ByteBuffer localBuf = buffer;
if (capacityRemaining(buffer) < 4) {
    localBuf = extendBuffer(buffer, BLOCK_SIZE);
localBuf.putInt(i);
return localBuf;
ByteBufferputIntArray(int ints[], ByteBuffer bb)
put Int Array
if (ints != null) {
    bb.putInt(ints.length);
    byte[] b = new byte[ints.length * 4];
    int l = 0;
    for (int i = 0; i < b.length;) {
        int x = ints[l++];
        b[i++] = (byte) (x >> 24);
        b[i++] = (byte) (x >> 16);
...
voidputIntByteBuffer(ByteBuffer buf, int b)
put Int Byte Buffer
buf.put((byte) (b & 0xFF));