Java Utililty Methods ByteBuffer Write

List of utility methods to do ByteBuffer Write

Description

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

Method

voidwriteUB2(ByteBuffer buffer, int i)
write UB
buffer.put((byte) (i & 0xff));
buffer.put((byte) (i >>> 8));
voidwriteUnsigned(int num, int size, ByteBuffer out)
write Unsigned
for (int i = 0; i < size; i++) {
    out.put((byte) num);
    num >>>= 8;
voidwriteUnsignedInt(ByteBuffer buf, long value)
Marshall a long into the next 4 bytes in this buffer.
buf.put((byte) (value >>> 0));
buf.put((byte) (value >>> 8));
buf.put((byte) (value >>> 16));
buf.put((byte) (value >>> 24));
voidwriteUnsignedInt(final ByteBuffer buffer, final long value)
Write the given long value as a 4 byte unsigned integer.
buffer.putInt((int) (value & 0xffffffffL));
voidwriteUnsignedVarInt(int value, ByteBuffer dest)
write Unsigned Var Int
while ((value & 0xFFFFFF80) != 0L) {
    dest.putInt((value & 0x7F) | 0x80);
    value >>>= 7;
dest.putInt(value & 0x7F);
voidwriteUTF8StringToByteBuffer(String str, ByteBuffer bb)
write UTF String To Byte Buffer
Charset charset = Charset.forName("UTF-8");
CharsetEncoder encoder = charset.newEncoder();
CharBuffer in = CharBuffer.wrap(str);
try {
    encoder.encode(in, bb, true);
    return;
} catch (Exception e) {
    e.printStackTrace();
...
voidwriteUUID(ByteBuffer buffer, UUID uuid)
write UUID
buffer.putLong(uuid.getMostSignificantBits());
buffer.putLong(uuid.getLeastSignificantBits());
voidwriteV(ByteBuffer byteBuffer, List vint)
write V
if (vint == null)
    return;
byteBuffer.putInt(vint.size());
for (int i = 0; i < vint.size(); ++i) {
    byteBuffer.putInt(vint.get(i));
voidwriteVarint(int value, ByteBuffer buffer)
Write the given integer following the variable-length zig-zag encoding from Google Protocol Buffers into the buffer.
int v = (value << 1) ^ (value >> 31);
while ((v & 0xffffff80) != 0L) {
    byte b = (byte) ((v & 0x7f) | 0x80);
    buffer.put(b);
    v >>>= 7;
buffer.put((byte) v);
voidwriteVarLong(ByteBuffer buff, long x)
Write a variable size int.
while ((x & ~0x7f) != 0) {
    buff.put((byte) (0x80 | (x & 0x7f)));
    x >>>= 7;
buff.put((byte) x);