/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] decode(byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a String where each char of the String represents an ASCII '0' or '1'. * * @param ascii * String of '0' and '1' characters * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }
/** * Decodes a String where each char of the String represents an ascii '0' or '1'. * * @param ascii * String of '0' and '1' characters * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] toByteArray(String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @throws DecoderException * if argument is not a byte[], char[] or String * @see org.apache.commons.codec.Decoder#decode(Object) */ @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"); }
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @throws DecoderException * if argument is not a byte[], char[] or String * @see org.apache.commons.codec.Decoder#decode(java.lang.Object) */ public Object decode(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"); }
@Test public void testFromAsciiByteArray() { assertEquals(0, BinaryCodec.fromAscii((byte[]) null).length); assertEquals(0, BinaryCodec.fromAscii(new byte[0]).length); byte[] decoded = BinaryCodec.fromAscii("00000000".getBytes(CHARSET_UTF8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0; decoded = BinaryCodec.fromAscii("00000001".getBytes(CHARSET_UTF8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1; decoded = BinaryCodec.fromAscii("00000011".getBytes(CHARSET_UTF8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2; decoded = BinaryCodec.fromAscii("00000111".getBytes(CHARSET_UTF8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3; decoded = BinaryCodec.fromAscii("00001111".getBytes(CHARSET_UTF8)); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4; decoded = BinaryCodec.fromAscii("00011111".getBytes(CHARSET_UTF8)); 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 = BinaryCodec.fromAscii("00111111".getBytes(CHARSET_UTF8));
@Test public void testFromAsciiCharArray() { assertEquals(0, BinaryCodec.fromAscii((char[]) null).length); assertEquals(0, BinaryCodec.fromAscii(new char[0]).length); byte[] decoded = BinaryCodec.fromAscii("00000000".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0; decoded = BinaryCodec.fromAscii("00000001".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1; decoded = BinaryCodec.fromAscii("00000011".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2; decoded = BinaryCodec.fromAscii("00000111".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3; decoded = BinaryCodec.fromAscii("00001111".toCharArray()); assertEquals(new String(bits), new String(decoded)); bits = new byte[1]; bits[0] = BIT_0 | BIT_1 | BIT_2 | BIT_3 | BIT_4; decoded = BinaryCodec.fromAscii("00011111".toCharArray()); 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 = BinaryCodec.fromAscii("00111111".toCharArray());
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] decode(byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] decode(byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] decode(byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ascii '0' or '1'. * * @param ascii * each byte represents an ascii '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] decode(byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a byte array where each byte represents an ASCII '0' or '1'. * * @param ascii * each byte represents an ASCII '0' or '1' * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ @Override public byte[] decode(final byte[] ascii) { return fromAscii(ascii); }
/** * Decodes a String where each char of the String represents an ascii '0' or '1'. * * @param ascii * String of '0' and '1' characters * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] toByteArray(String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }
/** * Decodes a String where each char of the String represents an ASCII '0' or '1'. * * @param ascii * String of '0' and '1' characters * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] toByteArray(final String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }
/** * Decodes a String where each char of the String represents an ascii '0' or '1'. * * @param ascii * String of '0' and '1' characters * @return the raw encoded binary where each bit corresponds to a byte in the byte array argument * @see org.apache.commons.codec.Decoder#decode(Object) */ public byte[] toByteArray(String ascii) { if (ascii == null) { return EMPTY_BYTE_ARRAY; } return fromAscii(ascii.toCharArray()); }