@Test public void testToByteArrayFromString() { byte[] bits = new byte[1]; byte[] decoded = instance.toByteArray("00000000"); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0; decoded = instance.toByteArray("00000001"); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1; decoded = instance.toByteArray("00000011"); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2; decoded = instance.toByteArray("00000111"); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3; decoded = instance.toByteArray("00001111"); 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.toByteArray("00011111"); 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.toByteArray("00111111"); 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.toByteArray("01111111"); 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.toByteArray("11111111"); 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.toByteArray("0000000011111111"); 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.toByteArray("0000000111111111"); 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.toByteArray("0000001111111111"); 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.toByteArray("0000011111111111"); 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.toByteArray("0000111111111111"); 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.toByteArray("0001111111111111"); 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.toByteArray("0011111111111111"); 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.toByteArray("0111111111111111"); 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.toByteArray("1111111111111111"); assertEquals(new String(bits), new String(decoded)); assertEquals(0, instance.toByteArray((String) null).length); }
public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }
BinaryCodec implements BinaryDecoder, BinaryEncoder { public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); } }
BinaryCodec implements BinaryDecoder, BinaryEncoder { public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }  }
BinaryCodec implements BinaryDecoder, BinaryEncoder { public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }  @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 { public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }  @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);  }