Fields Summary |
---|
private static final char[] | EMPTY_CHAR_ARRAYEmpty char array. |
private static final byte[] | EMPTY_BYTE_ARRAYEmpty byte array. |
private static final int | BIT_0Mask for bit 0 of a byte. |
private static final int | BIT_1Mask for bit 1 of a byte. |
private static final int | BIT_2Mask for bit 2 of a byte. |
private static final int | BIT_3Mask for bit 3 of a byte. |
private static final int | BIT_4Mask for bit 4 of a byte. |
private static final int | BIT_5Mask for bit 5 of a byte. |
private static final int | BIT_6Mask for bit 6 of a byte. |
private static final int | BIT_7Mask for bit 7 of a byte. |
private static final int[] | BITS |
Methods Summary |
---|
public java.lang.Object | decode(java.lang.Object ascii)Decodes a byte array where each byte represents an ascii '0' or '1'.
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");
|
public byte[] | decode(byte[] ascii)Decodes a byte array where each byte represents an ascii '0' or '1'.
return fromAscii(ascii);
|
public byte[] | encode(byte[] raw)Converts an array of raw binary data into an array of ascii 0 and 1 characters.
return toAsciiBytes(raw);
|
public java.lang.Object | encode(java.lang.Object raw)Converts an array of raw binary data into an array of ascii 0 and 1 chars.
if (!(raw instanceof byte[])) {
throw new EncoderException("argument not a byte array");
}
return toAsciiChars((byte[]) raw);
|
public static byte[] | fromAscii(char[] ascii)Decodes a byte array where each char represents an ascii '0' or '1'.
if (ascii == null || ascii.length == 0) {
return EMPTY_BYTE_ARRAY;
}
// get length/8 times bytes with 3 bit shifts to the right of the length
byte[] l_raw = new byte[ascii.length >> 3];
/*
* We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
* loop.
*/
for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if (ascii[jj - bits] == '1") {
l_raw[ii] |= BITS[bits];
}
}
}
return l_raw;
|
public static byte[] | fromAscii(byte[] ascii)Decodes a byte array where each byte represents an ascii '0' or '1'.
if (ascii == null || ascii.length == 0) {
return EMPTY_BYTE_ARRAY;
}
// get length/8 times bytes with 3 bit shifts to the right of the length
byte[] l_raw = new byte[ascii.length >> 3];
/*
* We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
* loop.
*/
for (int ii = 0, jj = ascii.length - 1; ii < l_raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if (ascii[jj - bits] == '1") {
l_raw[ii] |= BITS[bits];
}
}
}
return l_raw;
|
public 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.
if (raw == null || raw.length == 0) {
return EMPTY_BYTE_ARRAY;
}
// get 8 times the bytes with 3 bit shifts to the left of the length
byte[] l_ascii = new byte[raw.length << 3];
/*
* We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
* loop.
*/
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if ((raw[ii] & BITS[bits]) == 0) {
l_ascii[jj - bits] = '0";
} else {
l_ascii[jj - bits] = '1";
}
}
}
return l_ascii;
|
public static char[] | toAsciiChars(byte[] raw)Converts an array of raw binary data into an array of ascii 0 and 1 characters.
if (raw == null || raw.length == 0) {
return EMPTY_CHAR_ARRAY;
}
// get 8 times the bytes with 3 bit shifts to the left of the length
char[] l_ascii = new char[raw.length << 3];
/*
* We decr index jj by 8 as we go along to not recompute indices using multiplication every time inside the
* loop.
*/
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
for (int bits = 0; bits < BITS.length; ++bits) {
if ((raw[ii] & BITS[bits]) == 0) {
l_ascii[jj - bits] = '0";
} else {
l_ascii[jj - bits] = '1";
}
}
}
return l_ascii;
|
public static java.lang.String | toAsciiString(byte[] raw)Converts an array of raw binary data into a String of ascii 0 and 1 characters.
return new String(toAsciiChars(raw));
|
public byte[] | toByteArray(java.lang.String ascii)Decodes a String where each char of the String represents an ascii '0' or '1'.
if (ascii == null) {
return EMPTY_BYTE_ARRAY;
}
return fromAscii(ascii.toCharArray());
|