org.xins.logdoc
Class LogdocHexConverter

java.lang.Object
  extended byorg.xins.logdoc.LogdocHexConverter

public class LogdocHexConverter
extends Object

Utility class for converting numbers to unsigned hex strings and vice versa, specifically for Logdoc classes.

Since:
XINS 1.0.0
Version:
$Revision: 1.8 $ $Date: 2006/08/28 09:12:30 $
Author:
Ernst de Haan

Method Summary
static boolean isHexDigit(char c)
          Checks if the specified character is a hexadecimal digit.
static int parseHexInt(String s)
          Parses the specified 8-digit unsigned hex string.
static int parseHexInt(String s, int index)
          Parses the 8-digit unsigned hex number in the specified string.
static long parseHexLong(String s)
          Parses the specified 16-digit unsigned hex string.
static long parseHexLong(String s, int index)
          Parses the 16-digit unsigned hex number in the specified string.
static String toHexString(int n)
          Convert the specified int to an unsigned number hex string.
static void toHexString(LogdocStringBuffer buffer, int n)
          Converts the specified int to unsigned number and appends it to the specified string buffer.
static void toHexString(LogdocStringBuffer buffer, long n)
          Converts the specified long to unsigned number and appends it to the specified string buffer.
static String toHexString(long n)
          Convert the specified long to an unsigned number hex string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isHexDigit

public static final boolean isHexDigit(char c)
Checks if the specified character is a hexadecimal digit. The following ranges of characters are considered hexadecimal digits:

Parameters:
c - the character to check.
Returns:
true if the specified character is a hexadecimal digit, false otherwise.

toHexString

public static String toHexString(int n)
Convert the specified int to an unsigned number hex string. The returned string will always consist of 8 hex characters, zeroes will be prepended as necessary.

Parameters:
n - the number to be converted to a hex string.
Returns:
the hex string, cannot be null, the length is always 8 (i.e. return.length() == 8).

toHexString

public static String toHexString(long n)
Convert the specified long to an unsigned number hex string. The returned string will always consist of 16 hex characters, zeroes will be prepended as necessary.

Parameters:
n - the number to be converted to a hex string.
Returns:
the hex string, cannot be null, the length is always 16 (i.e. return.length() == 16).

toHexString

public static void toHexString(LogdocStringBuffer buffer,
                               int n)
                        throws IllegalArgumentException
Converts the specified int to unsigned number and appends it to the specified string buffer. Exactly 8 characters will be appended, all between '0' to '9' or between 'a' and 'f'.

Parameters:
buffer - the string buffer to append to, cannot be null.
n - the number to be converted to a hex string.
Throws:
IllegalArgumentException - if buffer == null.

toHexString

public static void toHexString(LogdocStringBuffer buffer,
                               long n)
                        throws IllegalArgumentException
Converts the specified long to unsigned number and appends it to the specified string buffer. Exactly 16 characters will be appended, all between '0' to '9' or between 'a' and 'f'.

Parameters:
buffer - the string buffer to append to, cannot be null.
n - the number to be converted to a hex string.
Throws:
IllegalArgumentException - if buffer == null.

parseHexLong

public static long parseHexLong(String s,
                                int index)
                         throws IllegalArgumentException,
                                NumberFormatException
Parses the 16-digit unsigned hex number in the specified string.

Parameters:
s - the hexadecimal string, cannot be null.
index - the starting index in the string, must be >= 0.
Returns:
the value of the parsed unsigned hexadecimal string.
Throws:
IllegalArgumentException - if s == null || index < 0 || s.length() < index + 16).
NumberFormatException - if any of the characters in the specified range of the string is not a hex digit ('0' to '9' and 'a' to 'f').

parseHexLong

public static long parseHexLong(String s)
                         throws IllegalArgumentException,
                                NumberFormatException
Parses the specified 16-digit unsigned hex string.

Parameters:
s - the hexadecimal string, cannot be null and must have size 16 (i.e. s.length() == 16).
Returns:
the value of the parsed unsigned hexadecimal string.
Throws:
IllegalArgumentException - if s == null || s.length() != 16.
NumberFormatException - if any of the characters in the specified string is not a hex digit ('0' to '9' and 'a' to 'f').

parseHexInt

public static int parseHexInt(String s,
                              int index)
                       throws IllegalArgumentException,
                              NumberFormatException
Parses the 8-digit unsigned hex number in the specified string.

Parameters:
s - the hexadecimal string, cannot be null.
index - the starting index in the string, must be >= 0.
Returns:
the value of the parsed unsigned hexadecimal string.
Throws:
IllegalArgumentException - if s == null || index < 0 || s.length() < index + 8).
NumberFormatException - if any of the characters in the specified range of the string is not a hex digit ('0' to '9' and 'a' to 'f').

parseHexInt

public static int parseHexInt(String s)
                       throws IllegalArgumentException,
                              NumberFormatException
Parses the specified 8-digit unsigned hex string.

Parameters:
s - the hexadecimal string, cannot be null and must have size 8 (i.e. s.length() == 8).
Returns:
the value of the parsed unsigned hexadecimal string.
Throws:
IllegalArgumentException - if s == null || s.length() != 8.
NumberFormatException - if any of the characters in the specified string is not a hex digit ('0' to '9' and 'a' to 'f').


See http://www.xins.org/.