Package com.oss.util

Class ByteTool

java.lang.Object
com.oss.util.ByteTool

public abstract class ByteTool extends Object
This class provides utility methods for testing and manipulating byte arrays.
Since:
ASN.1/Java 6.0
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static 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[]
    Take a decimal IP address, convert it to the binary format and return the result in a byte[] array.
    static byte[]
    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 the byte[] 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 the byte[] to text format.
    static String
    toTBCD(byte[] tbcd)
    Converts a Telephony Binary-Coded Decimal (TBCD) that is stored in the byte[] to the text format.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static String toBCD(byte[] bcd) throws NumberFormatException
      Converts a Binary-Coded Decimal that is stored in the byte[] to a decimal number.
      Parameters:
      bcd - the Binary-Coded Decimal.
      Returns:
      An unsigned decimal number.
      Throws:
      NumberFormatException - when the bcd violates the BCD format.
    • parseBCD

      public static byte[] parseBCD(String bcd) throws NumberFormatException
      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 the bcd string contains non-numeric characters.
    • toTAP3BCD

      public static String toTAP3BCD(byte[] tap3Bcd) throws NumberFormatException
      Converts a TAP3 Binary-Coded Decimal that is stored in the byte[] 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 the tap3Bcd violates the TAP3 BCD format.
    • parseTAP3BCD

      public static byte[] parseTAP3BCD(String tap3Bcd) throws NumberFormatException
      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 the tap3Bcd string contains characters that are not valid TAP3 BCD digits.
    • toTBCD

      public static String toTBCD(byte[] tbcd) throws NumberFormatException
      Converts a Telephony Binary-Coded Decimal (TBCD) that is stored in the byte[] 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 the tbcd violates the TBCD format.
    • parseTBCD

      public static byte[] parseTBCD(String tbcd) throws NumberFormatException
      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 the tbcd string contains characters that are not valid TBCD digits.
    • toIPAddress

      public static String toIPAddress(byte[] address) throws NumberFormatException
      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

      public static byte[] parseIPAddress(String address) throws NumberFormatException
      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 the address string is badly formatted.
    • include

      public static boolean include(byte[] array1, byte[] array2)