com.objsys.asn1j.runtime
Class Asn1Util

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1Util

public class Asn1Util
extends java.lang.Object

This class contains some general purpose static utility functions.


Constructor Summary
Asn1Util()
           
 
Method Summary
static java.lang.String BCDToString(byte[] bcd)
          Translates a BCD string to an ASCII string.
static byte[] decodeBase64Array(byte[] srcArray)
          Translates the specified Base64 array into byte array.
static byte[] encodeBase64Array(byte[] srcArray)
          Translates the specified byte array to Base64 byte array.
static int getBytesCount(long val)
          Calculate the count of bytes necessary to represent a signed long value.
static int getUlongBytesCount(long val)
          Calculate the count of bytes necessary to represent an unsigned long value.
static double log2(double val)
          Calculate the log base 2 of value
static byte[] stringToBCD(java.lang.String str)
          Translates an ASCII string to a BCD string.
static byte[] stringToTBCD(java.lang.String str)
          Translates an ASCII String to a TBCD String.
static java.lang.String TBCDToString(byte[] bcd)
          Translates a TBCD string to an ASCII string.
static java.lang.String toHexString(byte b)
          Convert a byte value to a hex string.
static java.lang.String toHexString(byte[] b, int offset, int nbytes)
          Convert a string of bytes into a hex string.
static java.lang.StringBuffer toHexString(byte b, java.lang.StringBuffer hexbuf)
          Convert a byte value to a hex string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Asn1Util

public Asn1Util()
Method Detail

toHexString

public static java.lang.String toHexString(byte b)
Convert a byte value to a hex string. Unlike the Java built-in function, this will: a. not sign extend the byte value out to 32 bits if the MSB is set, and b. put a zero padding byte in front if less than 0xf In other words, a character string of length 2 is always returned.


toHexString

public static java.lang.StringBuffer toHexString(byte b,
                                                 java.lang.StringBuffer hexbuf)
Convert a byte value to a hex string. Unlike the Java built-in function, this will: a. not sign extend the byte value out to 32 bits if the MSB is set, and b. put a zero padding byte in front if less than 0xf In other words, a character string of length 2 is always returned.


toHexString

public static java.lang.String toHexString(byte[] b,
                                           int offset,
                                           int nbytes)
Convert a string of bytes into a hex string.


getBytesCount

public static int getBytesCount(long val)
Calculate the count of bytes necessary to represent a signed long value.

Parameters:
val - Integer value in which to count bytes.
Returns:
Bit count.

log2

public static double log2(double val)
Calculate the log base 2 of value

Parameters:
val - double value for which to count lag(base2) val.
Returns:
result value.

getUlongBytesCount

public static int getUlongBytesCount(long val)
Calculate the count of bytes necessary to represent an unsigned long value.

Parameters:
val - Integer value in which to count bytes.
Returns:
Bit count.

encodeBase64Array

public static byte[] encodeBase64Array(byte[] srcArray)
Translates the specified byte array to Base64 byte array. The resulting array could be converted to the String by new String (byte[]) constructor.

Parameters:
srcArray - byte array to be translated
Returns:
Base64 encoded byte array

decodeBase64Array

public static byte[] decodeBase64Array(byte[] srcArray)
Translates the specified Base64 array into byte array. The resulting array could be converted to the String by new String (byte[]) constructor.

Parameters:
srcArray - Base64 byte array to be translated
Returns:
decoded byte array

stringToBCD

public static byte[] stringToBCD(java.lang.String str)
                          throws Asn1ValueParseException
Translates an ASCII string to a BCD string. The ASCII string must contain only characters in the range [0..9] & ([A..F] | [a..f]). If the length of the source string is not even, the unused part of the last byte will be set to 0xF.

Parameters:
str - the source ASCII string
Returns:
the BCD string as a byte array.
Throws:
Asn1ValueParseException - If invalid characters are in the source string.

BCDToString

public static java.lang.String BCDToString(byte[] bcd)
Translates a BCD string to an ASCII string. The 0xF half-byte is assumed as end of string indicator.

Parameters:
bcd - the source BCD string
Returns:
the ASCII string.

stringToTBCD

public static byte[] stringToTBCD(java.lang.String str)
                           throws Asn1ValueParseException
Translates an ASCII String to a TBCD String. TBCD strings are packed such that the least significant nibble occupies the upper four bits in each byte. The ASCII string "12345" would be encoded 0x2143f5.

Parameters:
str - the source ASCII string
Returns:
the BCD string as a byte array.
Throws:
Asn1ValueParseException - If invalid characters are in the source string.

TBCDToString

public static java.lang.String TBCDToString(byte[] bcd)
Translates a TBCD string to an ASCII string. The 0xF half-byte is assumed as end of string indicator.

Parameters:
bcd - the source TBCD string
Returns:
the ASCII string.