de.uplanet.util.encoder
Class HexEncoder

java.lang.Object
  extended by de.uplanet.util.encoder.HexEncoder

@Scriptable
public final class HexEncoder
extends java.lang.Object

Utility class for hex encoding and decoding.

Version:
1.00, 2000-09-28

Method Summary
static char[] byteToHex(byte p_byte)
          Returns a character array of 2 hexadecimal digits corresponding to a byte.
static char[] charToHex(int p_ch)
          Returns a character array of 4 hexadecimal digits (most significant digit first) corresponding to a char.
static byte[] decode(char[] p_achSrc)
          Returns a byte array from a character array of hexadecimal digits.
static byte[] decode(char[] p_achSrc, int p_iStart, int p_iLen)
          Returns a byte array from a character array of hexadecimal digits.
static byte[] decode(java.lang.CharSequence p_chseq, int p_iStart, int p_iLen)
          Returns a byte array from a character sequence of hexadecimal digits.
static char[] encode(byte[] p_ab)
          Returns a character array of hexadecimal digits from a byte array.
static char[] encode(byte[] p_ab, int p_iOffset, int p_iLength)
          Returns a string of hexadecimal digits from a byte array, starting at p_iOffset with length p_iLenghth.
static int hexDigitToInt(char p_ch)
          Returns the value of a hexadecimal digit as an int.
static char[] intToHex(int p_iArg)
          Returns a character array of 8 hexadecimal digits (most significant digit first) corresponding to an int.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hexDigitToInt

public static int hexDigitToInt(char p_ch)
                         throws java.lang.IllegalArgumentException
Returns the value of a hexadecimal digit as an int.

Parameters:
p_ch - Hexadecimal digit.
Returns:
Integer that corresponds to the hexadecimal digit.
Throws:
java.lang.IllegalArgumentException - If the digit is not hexadecimal.

byteToHex

public static char[] byteToHex(byte p_byte)
Returns a character array of 2 hexadecimal digits corresponding to a byte.

Parameters:
p_byte - Byte to encode.
Returns:
Hexadecimal representation of the byte.

charToHex

public static char[] charToHex(int p_ch)
Returns a character array of 4 hexadecimal digits (most significant digit first) corresponding to a char.

Parameters:
p_ch - Character to encode.
Returns:
Hexadecimal two byte representation of the character.

intToHex

public static char[] intToHex(int p_iArg)
Returns a character array of 8 hexadecimal digits (most significant digit first) corresponding to an int.

Parameters:
p_iArg - Integer to encode.
Returns:
Hexadecimal four byte representation of the integer.

encode

public static char[] encode(byte[] p_ab)
Returns a character array of hexadecimal digits from a byte array.

Parameters:
p_ab - Byte array to encode.
Returns:
A character array of hexadecimal digits that represents the byte array.

encode

public static char[] encode(byte[] p_ab,
                            int p_iOffset,
                            int p_iLength)
Returns a string of hexadecimal digits from a byte array, starting at p_iOffset with length p_iLenghth.

Parameters:
p_ab - Byte array to encode.
p_iOffset - Offset to start encoding.
p_iLength - Number of Bytes to encode.
Returns:
A character array of hexadecimal digits that represents the memory block.

decode

public static byte[] decode(char[] p_achSrc)
                     throws de.uplanet.util.encoder.EncoderException
Returns a byte array from a character array of hexadecimal digits.

Parameters:
p_achSrc - Character array of hexadecimal digits.
Returns:
The decoded byte array or null if p_achSrc is null or has zero length.
Throws:
EncoderException - If the input length is odd or if the input contains non-hexadecimal characters.

decode

public static byte[] decode(char[] p_achSrc,
                            int p_iStart,
                            int p_iLen)
                     throws de.uplanet.util.encoder.EncoderException
Returns a byte array from a character array of hexadecimal digits.

Parameters:
p_achSrc - Character array of hexadecimal digits.
p_iStart - The start index for decoding.
p_iLen - The number of hexadecimal digits to process.
Returns:
The decoded byte array.
Throws:
java.lang.IllegalArgumentException - If p_achSrc is null.
EncoderException - If p_iLen is odd or if the input contains non-hexadecimal characters.

decode

public static byte[] decode(java.lang.CharSequence p_chseq,
                            int p_iStart,
                            int p_iLen)
                     throws de.uplanet.util.encoder.EncoderException
Returns a byte array from a character sequence of hexadecimal digits.

Parameters:
p_chseq - A character sequence of hexadecimal digits.
p_iStart - The start index for decoding.
p_iLen - The number of hexadecimal digits to process.
Returns:
The decoded byte array or null if p_achSrc is null or p_iLen is 0.
Throws:
java.lang.IllegalArgumentException - If p_chseq is null.
EncoderException - If p_iLen is odd or if the input contains non-hexadecimal characters.


Last updated: 2011-08-11 10-04
Copyright © 2000-2011 United Planet. All Rights Reserved.