@Test public void testDecodeByteArray() { byte[] bits = new byte[1]; byte[] decoded = instance.decode("00000000".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0; decoded = instance.decode("00000001".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1; decoded = instance.decode("00000011".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2; decoded = instance.decode("00000111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3; decoded = instance.decode("00001111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4; decoded = instance.decode("00011111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5; decoded = instance.decode("00111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6; decoded = instance.decode("01111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("11111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0000000011111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0000000111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0000001111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1 | BIT_2; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0000011111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0000111111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0001111111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0011111111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6; bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("0111111111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[2]; bits[1] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); bits[0] = (byte) (BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4 | BIT_5 | BIT_6 | BIT_7); decoded = instance.decode("1111111111111111".getBytes(Charsets.UTF_8)); assertEquals(new String(bits), new String(decoded)); }
@Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (ascii instanceof String) { return fromAscii(((String) ascii).toCharArray()); } throw new DecoderException("argument not a byte array"); }
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (ascii instanceof String) { return fromAscii(((String) ascii).toCharArray()); } throw new DecoderException("argument not a byte array"); } }
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (ascii instanceof String) { return fromAscii(((String) ascii).toCharArray()); } throw new DecoderException("argument not a byte array"); }  }
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (ascii instanceof String) { return fromAscii(((String) ascii).toCharArray()); } throw new DecoderException("argument not a byte array"); }  @Override byte[] encode(final byte[] raw); @Override Object encode(final Object raw); @Override Object decode(final Object ascii); @Override byte[] decode(final byte[] ascii); byte[] toByteArray(final String ascii); static byte[] fromAscii(final char[] ascii); static byte[] fromAscii(final byte[] ascii); static byte[] toAsciiBytes(final byte[] raw); static char[] toAsciiChars(final byte[] raw); static String toAsciiString(final byte[] raw); }
BinaryCodec implements BinaryDecoder, BinaryEncoder { @Override public Object decode(final Object ascii) throws DecoderException { if (ascii == null) { return EMPTY_BYTE_ARRAY; } if (ascii instanceof byte[]) { return fromAscii((byte[]) ascii); } if (ascii instanceof char[]) { return fromAscii((char[]) ascii); } if (ascii instanceof String) { return fromAscii(((String) ascii).toCharArray()); } throw new DecoderException("argument not a byte array"); }  @Override byte[] encode(final byte[] raw); @Override Object encode(final Object raw); @Override Object decode(final Object ascii); @Override byte[] decode(final byte[] ascii); byte[] toByteArray(final String ascii); static byte[] fromAscii(final char[] ascii); static byte[] fromAscii(final byte[] ascii); static byte[] toAsciiBytes(final byte[] raw); static char[] toAsciiChars(final byte[] raw); static String toAsciiString(final byte[] raw);  }