public class BinaryCodec extends Object implements BinaryDecoder, BinaryEncoder
This class is immutable and thread-safe.
TODO: may want to add more bit vector functions like and/or/xor/nand TODO: also might be good to generate boolean[] from byte[] et cetera.Modifier and Type | Field and Description |
---|---|
private static int |
BIT_0
Mask for bit 0 of a byte.
|
private static int |
BIT_1
Mask for bit 1 of a byte.
|
private static int |
BIT_2
Mask for bit 2 of a byte.
|
private static int |
BIT_3
Mask for bit 3 of a byte.
|
private static int |
BIT_4
Mask for bit 4 of a byte.
|
private static int |
BIT_5
Mask for bit 5 of a byte.
|
private static int |
BIT_6
Mask for bit 6 of a byte.
|
private static int |
BIT_7
Mask for bit 7 of a byte.
|
private static int[] |
BITS |
private static byte[] |
EMPTY_BYTE_ARRAY
Empty byte array.
|
private static char[] |
EMPTY_CHAR_ARRAY
Empty char array.
|
Constructor and Description |
---|
BinaryCodec() |
Modifier and Type | Method and Description |
---|---|
byte[] |
decode(byte[] ascii)
Decodes a byte array where each byte represents an ASCII '0' or '1'.
|
Object |
decode(Object ascii)
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.
|
Object |
encode(Object raw)
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'.
|
private static boolean |
isEmpty(byte[] array)
Returns
true if the given array is null or empty (size 0.) |
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 String |
toAsciiString(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'.
|
private static final char[] EMPTY_CHAR_ARRAY
private static final byte[] EMPTY_BYTE_ARRAY
private static final int BIT_0
private static final int BIT_1
private static final int BIT_2
private static final int BIT_3
private static final int BIT_4
private static final int BIT_5
private static final int BIT_6
private static final int BIT_7
private static final int[] BITS
public BinaryCodec()
public byte[] encode(byte[] raw)
encode
in interface BinaryEncoder
raw
- the raw binary data to convertBinaryEncoder.encode(byte[])
public Object encode(Object raw) throws EncoderException
encode
in interface Encoder
raw
- the raw binary data to convertEncoderException
- if the argument is not a byte[]Encoder.encode(Object)
public Object decode(Object ascii) throws DecoderException
decode
in interface Decoder
ascii
- each byte represents an ASCII '0' or '1'DecoderException
- if argument is not a byte[], char[] or StringDecoder.decode(Object)
public byte[] decode(byte[] ascii)
decode
in interface BinaryDecoder
ascii
- each byte represents an ASCII '0' or '1'Decoder.decode(Object)
public byte[] toByteArray(String ascii)
ascii
- String of '0' and '1' charactersDecoder.decode(Object)
public static byte[] fromAscii(char[] ascii)
ascii
- each char represents an ASCII '0' or '1'public static byte[] fromAscii(byte[] ascii)
ascii
- each byte represents an ASCII '0' or '1'private static boolean isEmpty(byte[] array)
true
if the given array is null
or empty (size 0.)array
- the source arraytrue
if the given array is null
or empty (size 0.)public static byte[] toAsciiBytes(byte[] raw)
raw
- the raw binary data to convertBinaryEncoder.encode(byte[])
public static char[] toAsciiChars(byte[] raw)
raw
- the raw binary data to convertBinaryEncoder.encode(byte[])
public static String toAsciiString(byte[] raw)
raw
- the raw binary data to convertBinaryEncoder.encode(byte[])
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses