Java ByteBuffer Write writeVarLong(ByteBuffer buff, long x)

Here you can find the source of writeVarLong(ByteBuffer buff, long x)

Description

Write a variable size long.

License

Mozilla Public License

Parameter

Parameter Description
buff the target buffer
x the value

Declaration

public static void writeVarLong(ByteBuffer buff, long x) 

Method Source Code

//package com.java2s;
/*//from   w  ww .java2  s  .  c  o m
 * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0,
 * and the EPL 1.0 (http://h2database.com/html/license.html).
 * Initial Developer: H2 Group
 */

import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;

public class Main {
    /**
     * Write a variable size long.
     *
     * @param buff the target buffer
     * @param x the value
     */
    public static void writeVarLong(ByteBuffer buff, long x) {
        while ((x & ~0x7f) != 0) {
            buff.put((byte) (0x80 | (x & 0x7f)));
            x >>>= 7;
        }
        buff.put((byte) x);
    }

    /**
     * Write a variable size long.
     *
     * @param out the output stream
     * @param x the value
     */
    public static void writeVarLong(OutputStream out, long x) throws IOException {
        while ((x & ~0x7f) != 0) {
            out.write((byte) (0x80 | (x & 0x7f)));
            x >>>= 7;
        }
        out.write((byte) x);
    }
}

Related

  1. writeUTF8StringToByteBuffer(String str, ByteBuffer bb)
  2. writeUUID(ByteBuffer buffer, UUID uuid)
  3. writeV(ByteBuffer byteBuffer, List vint)
  4. writeVarint(int value, ByteBuffer buffer)
  5. writeVarLong(ByteBuffer buff, long x)
  6. writeVarLong(long n, ByteBuffer buff)
  7. writeVarLong(long value, ByteBuffer buf)
  8. writeVInt(ByteBuffer bb, int i)
  9. writeWithLength(ByteBuffer buffer, byte[] src)