org.apache.poi.contrib.poibrowser
Class Codec

java.lang.Object
  extended by org.apache.poi.contrib.poibrowser.Codec

public class Codec
extends java.lang.Object

Provides utility methods for encoding and decoding hexadecimal data.

Since:
2002-01-24
Version:
$Id: Codec.java 489730 2006-12-22 19:18:16Z bayard $
Author:
Rainer Klute (klute@rainer-klute.de) - with portions from Tomcat

Field Summary
protected static byte[] hexval
          The nibbles' hexadecimal values.
 
Constructor Summary
Codec()
           
 
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.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(ClassID classID)
          Converts a class ID 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 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

Codec

public Codec()
Method Detail

hexEncode

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

Converts a string into its hexadecimal notation.


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.


hexEncode

public static java.lang.String hexEncode(ClassID classID)

Converts a class ID 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

main

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

For testing.

Throws:
java.io.IOException


Copyright 2008 The Apache Software Foundation or its licensors, as applicable.