Class BinaryCodec
- All Implemented Interfaces:
BinaryDecoder, BinaryEncoder, Decoder, Encoder
This class is immutable and thread-safe.
- Since:
- 1.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decode(byte[] ascii) Decodes a byte array where each byte represents an ASCII '0' or '1'.Decodes a byte array where each byte represents an ASCII '0' or '1'.byte[]encode(byte[] raw) Converts an array of raw binary data into an array of ASCII 0 and 1 characters.Converts an array of raw binary data into an array of ASCII 0 and 1 chars.static byte[]fromAscii(byte[] ascii) Decodes a byte array where each byte represents an ASCII '0' or '1'.static byte[]fromAscii(char[] ascii) Decodes a char array where each char represents an ASCII '0' or '1'.static byte[]toAsciiBytes(byte[] raw) Converts an array of raw binary data into an array of ASCII 0 and 1 character bytes - each byte is a truncated char.static char[]toAsciiChars(byte[] raw) Converts an array of raw binary data into an array of ASCII 0 and 1 characters.static StringtoAsciiString(byte[] raw) Converts an array of raw binary data into a String of ASCII 0 and 1 characters.byte[]toByteArray(String ascii) Decodes a String where each char of the String represents an ASCII '0' or '1'.
-
Constructor Details
-
BinaryCodec
public BinaryCodec()Constructs a new instance.
-
-
Method Details
-
fromAscii
Decodes a byte array where each byte represents an ASCII '0' or '1'.All input must consist of ASCII
'0'and'1'values. If the input length is not a multiple of 8, the leadinglength % 8values are validated but omitted from the decoded result. Null or empty input produces an empty byte array.- Parameters:
ascii- each byte represents an ASCII '0' or '1'.- Returns:
- The raw encoded binary where each bit corresponds to a byte in the byte array argument.
- Throws:
IllegalArgumentException- Thrown if the input contains a value other than ASCII '0' or '1'.
-
fromAscii
Decodes a char array where each char represents an ASCII '0' or '1'.All input must consist of ASCII
'0'and'1'values. If the input length is not a multiple of 8, the leadinglength % 8values are validated but omitted from the decoded result. Null or empty input produces an empty byte array.- Parameters:
ascii- each char represents an ASCII '0' or '1'.- Returns:
- The raw encoded binary where each bit corresponds to a char in the char array argument.
- Throws:
IllegalArgumentException- Thrown if the input contains a value other than ASCII '0' or '1'.
-
toAsciiBytes
Converts an array of raw binary data into an array of ASCII 0 and 1 character bytes - each byte is a truncated char.- Parameters:
raw- The raw binary data to convert.- Returns:
- An array of 0 and 1 character bytes for each bit of the argument.
- See Also:
-
toAsciiChars
Converts an array of raw binary data into an array of ASCII 0 and 1 characters.- Parameters:
raw- The raw binary data to convert.- Returns:
- An array of 0 and 1 characters for each bit of the argument.
- See Also:
-
toAsciiString
Converts an array of raw binary data into a String of ASCII 0 and 1 characters.- Parameters:
raw- The raw binary data to convert.- Returns:
- A String of 0 and 1 characters representing the binary data.
- See Also:
-
decode
Decodes a byte array where each byte represents an ASCII '0' or '1'.All input must consist of ASCII
'0'and'1'values. If the input length is not a multiple of 8, the leadinglength % 8values are validated but omitted from the decoded result. Null or empty input produces an empty byte array.- Specified by:
decodein interfaceBinaryDecoder- Parameters:
ascii- each byte represents an ASCII '0' or '1'.- Returns:
- The raw encoded binary where each bit corresponds to a byte in the byte array argument.
- Throws:
IllegalArgumentException- Thrown if the input contains a value other than ASCII '0' or '1'.- See Also:
-
decode
Decodes a byte array where each byte represents an ASCII '0' or '1'.All input must consist of ASCII
'0'and'1'values. If the input length is not a multiple of 8, the leadinglength % 8values are validated but omitted from the decoded result. Null or empty input produces an empty byte array.- Specified by:
decodein interfaceDecoder- Parameters:
ascii- each byte represents an ASCII '0' or '1'.- Returns:
- The raw encoded binary where each bit corresponds to a byte in the byte array argument.
- Throws:
IllegalArgumentException- Thrown if the input contains a value other than ASCII '0' or '1'.DecoderException- Thrown if the argument is not a byte[], char[], or String.- See Also:
-
encode
Converts an array of raw binary data into an array of ASCII 0 and 1 characters.- Specified by:
encodein interfaceBinaryEncoder- Parameters:
raw- The raw binary data to convert.- Returns:
- 0 and 1 ASCII character bytes one for each bit of the argument.
- See Also:
-
encode
Converts an array of raw binary data into an array of ASCII 0 and 1 chars.- Specified by:
encodein interfaceEncoder- Parameters:
raw- The raw binary data to convert.- Returns:
- 0 and 1 ASCII character chars one for each bit of the argument.
- Throws:
EncoderException- Thrown if the argument is not a byte[].- See Also:
-
toByteArray
Decodes a String where each char of the String represents an ASCII '0' or '1'.All input must consist of ASCII
'0'and'1'values. If the input length is not a multiple of 8, the leadinglength % 8values are validated but omitted from the decoded result. Null or empty input produces an empty byte array.- Parameters:
ascii- String of '0' and '1' characters.- Returns:
- The raw encoded binary where each bit corresponds to a byte in the byte array argument.
- Throws:
IllegalArgumentException- Thrown if the input contains a value other than ASCII '0' or '1'.- See Also:
-