Framework Professional Edition Package


com.prosyst.util.encode
Class Hex

java.lang.Object
  extended by com.prosyst.util.encode.Hex

public final class Hex
extends java.lang.Object

This class encodes a binary data into a HEX representation string. The encoded string contains each byte of the binary data, represented by its hexa-decimal value, and separated by dash (-) symbol. As example, the Java byte array:

0, 15, 33
encodes as
0-f-21

Author:
Plamen Kossev, Valentin Valchev

Constructor Summary
Hex()
           
 
Method Summary
static byte[] decode(java.lang.String input)
          Decodes HEX form a String.
static java.lang.String encode(byte[] data)
          Encodes byte[] into HEX.
static java.lang.String encode(byte[] data, int start, int length)
          Encodes the a portion of a given binary data into a HEX string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Hex

public Hex()
Method Detail

encode

public static final java.lang.String encode(byte[] data)
Encodes byte[] into HEX.

Parameters:
data - byte[]
Returns:
String which contains encoded in HEX bytes If byte[] is with length 0 returns an empty String

encode

public static final java.lang.String encode(byte[] data,
                                            int start,
                                            int length)
Encodes the a portion of a given binary data into a HEX string

Parameters:
data - the binary data, that will be encoded
start - the start index, from which the data will be read
length - the number of elements to be extracted from the byte array
Returns:
the encoded binary data

decode

public static final byte[] decode(java.lang.String input)
                           throws java.lang.Exception
Decodes HEX form a String. The new line (\n) and carriage return (\r) symbols in the string are ignored.

Parameters:
input - the HEX encoded string, that will be decoded
Returns:
the decoded binary, byte array data
Throws:
java.lang.Exception
java.lang.Exception - if illegal hex block is detected (e.g. the number of symbols is more than 2), if illegal character is detected in the encoded string - a one, that is not a hex digit, dash (-), new line (\n) or carriage return (\r).

Framework Professional Edition Package


Copyright © 1999-2007 ProSyst Software GmbH. All Rights Reserved