Numbers { public static byte[] serializeLong(Long value) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); writeLong(value, stream); return stream.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } }  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_Size() throws Exception { assertArrayEquals(new byte[]{-128, 1}, Numbers.serializeLong(64L, 2)); assertArrayEquals(new byte[]{-128, -127, 0}, Numbers.serializeLong(64L, 3)); }
@Test(expected = IllegalArgumentException.class) public void testWriteLong_SmallSize() throws Exception { Numbers.serializeLong(64L, 1); }