Bytes { public static final void setLong(long value, byte[]b) { setLong(value, b, 0) ; } private  Bytes(); static int compare(byte[] x1, byte[] x2); static int compareByte(byte b1, byte b2); static byte[] copyOf(byte[] bytes); static byte[] copyOf(byte[] bytes, int start); static byte[] copyOf(byte[] bytes, int start, int length); static byte[] intToBytes(int v); static byte[] longToBytes(long v); static final int getInt(byte[]b); static final int getInt(byte[]b, int idx); static final long getLong(byte[]b); static final long getLong(byte[]b, int idx); static final void setInt(int value, byte[]b); static final void setInt(int x, byte[]b, int idx); static final void setLong(long value, byte[]b); static final void setLong(long value, byte[] b, int idx); static byte[] packInt(int val); static byte[] packLong(long val); static byte[] string2bytes(String x); static String bytes2string(byte[] x); static int toByteBuffer(CharSequence s, ByteBuffer bb); static int toByteBuffer(CharSequence s, ByteBuffer bb, CharsetEncoder enc); static String fromByteBuffer(ByteBuffer bb); static String fromByteBuffer(ByteBuffer bb, CharsetDecoder dec); static String asHex(byte[] bytes); static String asHexUC(byte[] bytes); static String asHexLC(byte[] bytes); static String asHex(byte[] bytes, int start, int finish, char[] hexDigits); static String asHex(byte b); static String asHexUC(byte b); static String asHexLC(byte b); static int hexCharToInt(char c); final static byte[] hexDigitsUC; final static byte[] hexDigitsLC; }
@Test public void packLong5() { byte[] b = new byte[8]; Bytes.setLong(0x0102030405060708L,b); assertEquals(0x01, b[0]); assertEquals(0x02, b[1]); assertEquals(0x03, b[2]); assertEquals(0x04, b[3]); assertEquals(0x05, b[4]); assertEquals(0x06, b[5]); assertEquals(0x07, b[6]); assertEquals(0x08, b[7]); }
@Test public void packLong6() { byte[] b = new byte[16]; Bytes.setLong(0x0102030405060708L,b,0); Bytes.setLong(0x1112131415161718L,b,8); assertEquals(0x01, b[0]); assertEquals(0x02, b[1]); assertEquals(0x03, b[2]); assertEquals(0x04, b[3]); assertEquals(0x05, b[4]); assertEquals(0x06, b[5]); assertEquals(0x07, b[6]); assertEquals(0x08, b[7]); assertEquals(0x11, b[0+8]); assertEquals(0x12, b[1+8]); assertEquals(0x13, b[2+8]); assertEquals(0x14, b[3+8]); assertEquals(0x15, b[4+8]); assertEquals(0x16, b[5+8]); assertEquals(0x17, b[6+8]); assertEquals(0x18, b[7+8]); }