xflow.util
Class HexUtil

java.lang.Object
  extended byxflow.util.HexUtil

public class HexUtil
extends java.lang.Object


Field Summary
protected static byte[] hexval
          The nibbles' hexadecimal values.
 
Constructor Summary
HexUtil()
           
 
Method Summary
protected static byte decodeNibble(char c)
          Decodes a nibble.
static byte[] hexDecode(java.lang.String s)
          Decodes the hexadecimal representation of a sequence of bytes into a byte array.
static java.lang.Object hexDecodeObject(java.lang.String bytes)
           
static java.lang.String hexEncode(byte b)
          Converts a single byte into its hexadecimal notation.
static java.lang.String hexEncode(byte[] s)
          Converts a byte array into its hexadecimal notation.
static java.lang.String hexEncode(byte[] s, int offset, int length)
          Converts a part of a byte array into its hexadecimal notation.
static java.lang.String hexEncode(int i)
          Converts an int value (32-bit) into its hexadecimal notation.
static java.lang.String hexEncode(long l)
          Converts a long value (64-bit) into its hexadecimal notation.
static java.lang.String hexEncode(short s)
          Converts a short value (16-bit) into its hexadecimal notation.
static java.lang.String hexEncode(java.lang.String s)
          Converts a string into its hexadecimal notation.
static java.lang.String hexEncodeObject(java.lang.Object obj)
           
static void main(java.lang.String[] args)
          For testing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexval

protected static final byte[] hexval

The nibbles' hexadecimal values. A nibble is a half byte.

Constructor Detail

HexUtil

public HexUtil()
Method Detail

hexEncode

public static java.lang.String hexEncode(java.lang.String s)

Converts a string into its hexadecimal notation.

FIXME: If this method is called frequently, it should directly implement the algorithm in the called method in order to avoid creating a string instance.


hexEncode

public static java.lang.String hexEncode(byte[] s)

Converts a byte array into its hexadecimal notation.


hexEncode

public static java.lang.String hexEncode(byte[] s,
                                         int offset,
                                         int length)

Converts a part of a byte array into its hexadecimal notation.


hexEncode

public static java.lang.String hexEncode(byte b)

Converts a single byte into its hexadecimal notation.


hexEncode

public static java.lang.String hexEncode(short s)

Converts a short value (16-bit) into its hexadecimal notation.


hexEncode

public static java.lang.String hexEncode(int i)

Converts an int value (32-bit) into its hexadecimal notation.


hexEncode

public static java.lang.String hexEncode(long l)

Converts a long value (64-bit) into its hexadecimal notation.


hexDecode

public static byte[] hexDecode(java.lang.String s)

Decodes the hexadecimal representation of a sequence of bytes into a byte array. Each character in the string represents a nibble (half byte) and must be one of the characters '0'-'9', 'A'-'F' or 'a'-'f'.

Parameters:
s - The string to be decoded
Returns:
The bytes
Throws:
java.lang.IllegalArgumentException - if the string does not contain a valid representation of a byte sequence.

decodeNibble

protected static byte decodeNibble(char c)

Decodes a nibble.

Parameters:
c - A character in the range '0'-'9' or 'A'-'F'. Lower case is not supported here.
Returns:
The decoded nibble in the range 0-15
Throws:
java.lang.IllegalArgumentException - if c is not a permitted character

hexEncodeObject

public static java.lang.String hexEncodeObject(java.lang.Object obj)

hexDecodeObject

public static java.lang.Object hexDecodeObject(java.lang.String bytes)

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException

For testing.

Throws:
java.io.IOException