CompactEncoder { public static byte[] binToNibbles(byte[] str) { byte[] hexEncoded = encode(str); byte[] hexEncodedTerminated = Arrays.copyOf(hexEncoded, hexEncoded.length + 1); for (int i = 0; i < hexEncoded.length; ++i){ byte b = hexEncodedTerminated[i]; hexEncodedTerminated[i] = hexMap.get((char) b); } hexEncodedTerminated[hexEncodedTerminated.length - 1] = TERMINATOR; return hexEncodedTerminated; }  static byte[] packNibbles(byte[] nibbles); static boolean hasTerminator(byte[] packedKey); 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)); }