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

voidwriteLong(long num, ByteBuffer out)
write Long
for (int i = 0; i < 8; i++) {
    out.put((byte) num);
    num >>>= 8;
voidwriteLong(long v, ByteBuffer buffer)
write Long
buffer.order(ByteOrder.LITTLE_ENDIAN);
buffer.putLong(v);
buffer.order(ByteOrder.BIG_ENDIAN);
voidwriteLTriad(int triad, ByteBuffer bb)
write L Triad
bb.put(writeLTriad(triad));
voidwriteNullTerminatedString(ByteBuffer buf, String s, String encoding)
write Null Terminated String
buf.put(s.getBytes(encoding));
buf.put((byte) 0);
voidwritePackageName(ByteBuffer buffer, String packageName)
Writes the provided package name to the buffer in UTF-16.
buffer.put(packageName.getBytes(Charset.forName("UTF-16LE")), 0, PACKAGE_NAME_SIZE);
voidwriteRemaining(WritableByteChannel channel, ByteBuffer buffer)
write Remaining
int noopCountDown = MAX_NOOP_TRIALS;
while (buffer.hasRemaining()) {
    if (channel.write(buffer) == 0) {
        if (--noopCountDown == 0)
            throw new IOException("Write failed after " + MAX_NOOP_TRIALS + " trials");
        continue;
    noopCountDown = MAX_NOOP_TRIALS;
...
voidwriteResBit15(int value, ByteBuffer toBuffer)
write Res Bit
if (value < 0x80) {
    toBuffer.put((byte) value);
} else {
    toBuffer.putShort((short) (value | 0x8000));
voidwriteShortString(ByteBuffer buffer, String s)
Write a size prefixed string where the size is stored as a 2 byte short
if (s == null) {
    buffer.putShort((short) -1);
} else if (s.length() > Short.MAX_VALUE) {
    throw new IllegalArgumentException("String exceeds the maximum size of " + Short.MAX_VALUE + ".");
} else {
    byte[] data = getBytes(s); 
    buffer.putShort((short) data.length);
    buffer.put(data);
...
voidwriteSign(ByteBuffer bb)
write Sign
bb.put(SIGN);
voidwriteSignedVarint(ByteBuffer buffer, int val)
Write an signed integer using a variable-length encoding.
writeUnsignedVarint(buffer, (val << 1) ^ (val >> 31));