Here you can find the source of encodeUint(OutputStream out, final long value)
public static boolean encodeUint(OutputStream out, final long value) throws IOException
//package com.java2s; // license that can be found in the LICENSE file. import java.io.IOException; import java.io.OutputStream; public class Main { /**/*from www . j a v a 2 s .c o m*/ * Unsigned integers are the basis for all other primitive values. This is a two-state encoding. * If the number is less than 128 (0 through 0x7f), its value is written directly. Otherwise the * value is written in big-endian byte order preceded by the negated byte length. * Returns true iff the value is non-zero. */ public static boolean encodeUint(OutputStream out, final long value) throws IOException { if ((value & 0x7f) == value) { out.write((byte) value); return value != 0; } int len = 0; while (((value >>> (len * 8)) | 0xff) != 0xff) { len++; } len++; out.write(-len); while (len > 0) { len--; out.write((byte) (value >>> (len * 8))); } return true; } public static boolean encodeUint(OutputStream out, final int value) throws IOException { return encodeUint(out, value & 0xffffffffL); } public static boolean encodeUint(OutputStream out, final short value) throws IOException { return encodeUint(out, value & 0xffffL); } }