Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

org.objectweb.cjdbc.common.stream.encoding.HexaEncoding Class Reference

List of all members.

Static Public Member Functions

final String data2hex (byte[] data)
final byte[] hex2data (String str)
char toHexChar (int i)
byte toDataNibble (char c)

Detailed Description

This class implements Hexa encoding and decoding

Author:
Nicolas Modrzyk
Version:
1.0

Definition at line 33 of file HexaEncoding.java.


Member Function Documentation

final String org.objectweb.cjdbc.common.stream.encoding.HexaEncoding.data2hex byte[]  data  )  [static]
 

Convert data into hexa

Parameters:
data to convert
Returns:
the converted string

Definition at line 41 of file HexaEncoding.java.

00042   {
00043     if (data == null)
00044       return null;
00045 
00046     int len = data.length;
00047     StringBuffer buf = new StringBuffer(len * 2);
00048     for (int pos = 0; pos < len; pos++)
00049       buf.append(toHexChar((data[pos] >>> 4) & 0x0F)).append(
00050           toHexChar(data[pos] & 0x0F));
00051     return buf.toString();
00052   }

final byte [] org.objectweb.cjdbc.common.stream.encoding.HexaEncoding.hex2data String  str  )  [static]
 

convert hexa into data

Parameters:
str to convert
Returns:
the converted byte array

Definition at line 60 of file HexaEncoding.java.

00061   {
00062     if (str == null)
00063       return new byte[0];
00064 
00065     int len = str.length();
00066     char hex[] = str.toCharArray();
00067     byte[] buf = new byte[len / 2];
00068 
00069     for (int pos = 0; pos < len / 2; pos++)
00070       buf[pos] = (byte) (((toDataNibble(hex[2 * pos]) << 4) & 0xF0) | (toDataNibble(hex[2 * pos + 1]) & 0x0F));
00071 
00072     return buf;
00073   }

byte org.objectweb.cjdbc.common.stream.encoding.HexaEncoding.toDataNibble char  c  )  [static]
 

convert hexa char to byte value

Parameters:
c hexa character
Returns:
corresponding byte value

Definition at line 95 of file HexaEncoding.java.

00096   {
00097     if (('0' <= c) && (c <= '9'))
00098       return (byte) ((byte) c - (byte) '0');
00099     else if (('a' <= c) && (c <= 'f'))
00100       return (byte) ((byte) c - (byte) 'a' + 10);
00101     else if (('A' <= c) && (c <= 'F'))
00102       return (byte) ((byte) c - (byte) 'A' + 10);
00103     else
00104       return -1;
00105   }

char org.objectweb.cjdbc.common.stream.encoding.HexaEncoding.toHexChar int  i  )  [static]
 

convert value to hexa value

Parameters:
i byte to convert
Returns:
hexa char

Definition at line 81 of file HexaEncoding.java.

00082   {
00083     if ((0 <= i) && (i <= 9))
00084       return (char) ('0' + i);
00085     else
00086       return (char) ('a' + (i - 10));
00087   }


The documentation for this class was generated from the following file:
Generated on Mon Apr 11 22:02:13 2005 for C-JDBC by  doxygen 1.3.9.1