HexUtil (fawkeZ - Developer's Documentation)

org.jcoderz.commons.util
Class HexUtil

  extended by org.jcoderz.commons.util.HexUtil

public final class HexUtil
extends

This class converts byte array data from and to hex and also provides a hexdump method.

Author:
Albrecht Messner

Method Summary
static  bytesToHex(byte[] data)
          Converts a byte array into an upper-case hex string, starting at the first byte and converting the whole array.
static  bytesToHex(byte[] data, int offset, int length)
          Converts a byte array into an upper-case hex string, starting at the given offset and converting the given number of bytes.
static  dump(byte[] data)
          Produces a hexdump of the given byte array with a formatting as in "hexdump -C" (canonical hex + ASCII display).
static byte[] stringToBytes( s)
          Convert the given hex string to a byte array.
 
Methods inherited from class java.lang.
, , , , , , , , , ,
 

Method Detail

bytesToHex

public static  bytesToHex(byte[] data,
                                int offset,
                                int length)
                         throws 
Converts a byte array into an upper-case hex string, starting at the given offset and converting the given number of bytes.

Parameters:
data - the byte data to convert to hex
offset - the start offset in the byte array
length - the number of bytes to convert
Returns:
null if data was null, an empty string if data.length == 0, and the hex representation of the byte array otherwise
Throws:
- if offset + length > data.lenght

bytesToHex

public static  bytesToHex(byte[] data)
Converts a byte array into an upper-case hex string, starting at the first byte and converting the whole array.

Parameters:
data - the byte data to convert to hex
Returns:
null if data was null, an empty string if data.length == 0, and the hex representation of the byte array otherwise

stringToBytes

public static byte[] stringToBytes( s)
                            throws 
Convert the given hex string to a byte array.

Parameters:
s - the string to convert
Returns:
null if the string is null, an empty byte array if s.length == 0 and a byte array representing the hex string otherwise
Throws:
- if the string is not a multiple of 2 characters long, or if the string contains an invalid hex char

dump

public static  dump(byte[] data)
Produces a hexdump of the given byte array with a formatting as in "hexdump -C" (canonical hex + ASCII display). This formatting contains an address column, sixteen bytes of hex separated by spaces, with an extra space after eight bytes, and an ascii print-out of the bytes enclosed in pipe symbols. Non-ASCII characters are replaced by dots.

Parameters:
data - the byte data to dump
Returns:
a string containing the hexdump, or null if data was null


Copyright 2007 The jCoderZ Project.