CompactEncoder { public static byte[] binToNibbles(byte[] str) { byte[] hexEncoded = encode(str); ByteBuffer slice = ByteBuffer.allocate(hexEncoded.length + 1); for (byte b : hexEncoded) { slice.put(hexMap.get((char)b)); } slice.put(TERMINATOR); return slice.array(); }  static byte[] packNibbles(byte[] nibbles); static byte[] unpackToNibbles(byte[] str); static byte[] binToNibbles(byte[] str); static byte[] binToNibblesNoTerminator(byte[] str);  }
@Test public void testCompactHexEncode_1() { byte[] test = "stallion".getBytes(); byte[] result = new byte[] { 7, 3, 7, 4, 6, 1, 6, 12, 6, 12, 6, 9, 6, 15, 6, 14, T }; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); }
@Test public void testCompactHexEncode_2() { byte[] test = "verb".getBytes(); byte[] result = new byte[] { 7, 6, 6, 5, 7, 2, 6, 2, T }; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); }
@Test public void testCompactHexEncode_3() { byte[] test = "puppy".getBytes(); byte[] result = new byte[] { 7, 0, 7, 5, 7, 0, 7, 0, 7, 9, T }; assertArrayEquals(result, CompactEncoder.binToNibbles(test)); }