Here you can find the source of writeLength(ByteBuffer buffer, long l)
public static final void writeLength(ByteBuffer buffer, long l)
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static final void writeLength(ByteBuffer buffer, long l) { if (l < 251) { buffer.put((byte) l); } else if (l < 0x10000L) { buffer.put((byte) 252); writeUB2(buffer, (int) l); } else if (l < 0x1000000L) { buffer.put((byte) 253); writeUB3(buffer, (int) l); } else {/* ww w.jav a 2s . c o m*/ buffer.put((byte) 254); writeLong(buffer, l); } } public static final void writeUB2(ByteBuffer buffer, int i) { buffer.put((byte) (i & 0xff)); buffer.put((byte) (i >>> 8)); } public static final void writeUB3(ByteBuffer buffer, int i) { buffer.put((byte) (i & 0xff)); buffer.put((byte) (i >>> 8)); buffer.put((byte) (i >>> 16)); } public static final void writeLong(ByteBuffer buffer, long l) { buffer.put((byte) (l & 0xff)); buffer.put((byte) (l >>> 8)); buffer.put((byte) (l >>> 16)); buffer.put((byte) (l >>> 24)); buffer.put((byte) (l >>> 32)); buffer.put((byte) (l >>> 40)); buffer.put((byte) (l >>> 48)); buffer.put((byte) (l >>> 56)); } }