Package com.oss.util
Class ByteTool
java.lang.Object
com.oss.util.ByteTool
This class provides utility methods for testing and manipulating
byte arrays.
- Since:
- ASN.1/Java 6.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
compare
(byte[] array1, byte[] array2) Compare two byte arrays for equality.static byte[]
copy
(byte[] src) Create a copy of an array of bytes.static boolean
include
(byte[] array1, byte[] array2) static byte[]
Parses a string containing an unsigned decimal number and converts it to the Binary-Coded Decimal representation.static byte[]
parseIPAddress
(String address) Take a decimal IP address, convert it to the binary format and return the result in a byte[] array.static byte[]
parseTAP3BCD
(String tap3Bcd) Parses a string containing one or more '0'-'9', 'a', 'b', 'c', 'd' and 'e' digits and converts it to the Binary-Coded Decimal representation.static byte[]
Parses a string containing one or more '0'-'9', 'a', 'b', 'c', '+' and '#' digits and converts it to the Telephony Binary-Coded Decimal representation.static String
toBCD
(byte[] bcd) Converts a Binary-Coded Decimal that is stored in thebyte[]
to a decimal number.static String
toIPAddress
(byte[] address) Interpret the four leading octets of the byte[] array as the IP address and convert it to decimal format.static String
toTAP3BCD
(byte[] tap3Bcd) Converts a TAP3 Binary-Coded Decimal that is stored in thebyte[]
to text format.static String
toTBCD
(byte[] tbcd) Converts a Telephony Binary-Coded Decimal (TBCD) that is stored in thebyte[]
to the text format.
-
Constructor Details
-
ByteTool
public ByteTool()
-
-
Method Details
-
compare
public static boolean compare(byte[] array1, byte[] array2) Compare two byte arrays for equality.- Parameters:
array1
- is one byte array.array2
- is another byte array.- Returns:
- true if "array1" references the same array of bytes as "array2" or both are null or the contents of "array1" is equal to the contents of "array2".
-
copy
public static byte[] copy(byte[] src) Create a copy of an array of bytes.- Parameters:
src
- is the byte array to make an exact copy of.- Returns:
- an exact copy of the input byte array.
-
toBCD
Converts a Binary-Coded Decimal that is stored in thebyte[]
to a decimal number.- Parameters:
bcd
- the Binary-Coded Decimal.- Returns:
- An unsigned decimal number.
- Throws:
NumberFormatException
- when thebcd
violates the BCD format.
-
parseBCD
Parses a string containing an unsigned decimal number and converts it to the Binary-Coded Decimal representation. The Binary-Coded Decimal representation packs each pair of digits into a single octet where the most significant digit occupies bits 7..4, and the least significant digit occupies bits 3..0.- Parameters:
bcd
- the unsigned decimal number.- Returns:
- The Binary-Coded Decimal stored in the
byte[]
. - Throws:
NumberFormatException
- when thebcd
string contains non-numeric characters.
-
toTAP3BCD
Converts a TAP3 Binary-Coded Decimal that is stored in thebyte[]
to text format. The TAP3 Binary-Coded Decimal can contain 'a', 'b', 'c', 'd', and 'e' digits in addition to '0'-'9'.- Parameters:
tap3Bcd
- the TAP3 Binary-Coded Decimal.- Returns:
- The string representing the TAP3 Binary-Coded Decimal number.
- Throws:
NumberFormatException
- when thetap3Bcd
violates the TAP3 BCD format.
-
parseTAP3BCD
Parses a string containing one or more '0'-'9', 'a', 'b', 'c', 'd' and 'e' digits and converts it to the Binary-Coded Decimal representation. The Binary-Coded Decimal representation packs each pair of digits into a single octet where the most significant digit occupies bits 7..4, and the least significant digit occupies bits 3..0.- Parameters:
tap3Bcd
- the string representing the TAP3 Binary-Coded Decimal number.- Returns:
- The TAP3 Binary-Coded Decimal stored in the
byte[]
. - Throws:
NumberFormatException
- when thetap3Bcd
string contains characters that are not valid TAP3 BCD digits.
-
toTBCD
Converts a Telephony Binary-Coded Decimal (TBCD) that is stored in thebyte[]
to the text format. The TBCD can contain 'a', 'b', 'c', '*' and '#' digits in addition to '0'-'9'.- Parameters:
tbcd
- the Telephony Binary-Coded Decimal.- Returns:
- The string representing the Telephony Binary-Coded Decimal number.
- Throws:
NumberFormatException
- when thetbcd
violates the TBCD format.
-
parseTBCD
Parses a string containing one or more '0'-'9', 'a', 'b', 'c', '+' and '#' digits and converts it to the Telephony Binary-Coded Decimal representation. The Telephony Binary-Coded Decimal representation packs each pair of digits into a single octet where the most significant digit occupies bits 3..0, and the least significant digit occupies bits 7..4.- Parameters:
tbcd
- the string representing the Telephony Binary-Coded Decimal number.- Returns:
- The Telephony Binary-Coded Decimal stored in the
byte[]
. - Throws:
NumberFormatException
- when thetbcd
string contains characters that are not valid TBCD digits.
-
toIPAddress
Interpret the four leading octets of the byte[] array as the IP address and convert it to decimal format.- Returns:
- the string that contains the IP address in the format "192.168.152.103".
- Throws:
NumberFormatException
- if the byte[] array contains less than 4 octets.
-
parseIPAddress
Take a decimal IP address, convert it to the binary format and return the result in a byte[] array.- Parameters:
address
- the string that contains the IP address in the format "192.168.152.103".- Returns:
- byte[] array with fixed length of 4 octets that contains the binary representation of the IP address.
- Throws:
NumberFormatException
- if theaddress
string is badly formatted.
-
include
public static boolean include(byte[] array1, byte[] array2)
-