Numbers { public static void writeLong(Long value, OutputStream stream) throws IOException { if (value == null) { stream.write(1); } else { writeLong(value.longValue(), stream); } }  static byte[] serializeLong(Long value); static byte[] serializeLong(Long value, int size); static int getSerializedSize(long value); static void writeLong(Long value, OutputStream stream); static void writeLong(long value, OutputStream stream); static Long readLong(InputStream stream); static final int MAX_LONG_SIZE; static final int MAX_INT_SIZE; }
@Test public void testWriteLong() throws Exception { checkWrite(new byte[]{0}, 0L); checkWrite(new byte[]{1}, null); checkWrite(new byte[]{2}, 1L); checkWrite(new byte[]{3}, -1L); checkWrite(new byte[]{126}, 63L); checkWrite(new byte[]{127}, -63L); checkWrite(new byte[]{-128, 1}, 64L); checkWrite(new byte[]{-127, 1}, -64L); assertEquals(10, Numbers.getSerializedSize(Long.MAX_VALUE)); assertEquals(10, Numbers.getSerializedSize(Long.MIN_VALUE)); }