org.mmbase.util
Class Encode

java.lang.Object
  |
  +--org.mmbase.util.Encode

public class Encode
extends java.lang.Object

Class to convert from/to a string (byte[]) from/to a encoded string (byte[])

Author:
Eduard Witteveen, Michiel Meeuwissen

Constructor Summary
Encode(java.lang.String encoding)
          Created a encode instance of a certain type of encoding.
 
Method Summary
 java.lang.String decode(java.lang.String toDecode)
          This function will decode a given string to it's decoded variant
static java.lang.String decode(java.lang.String encoding, java.lang.String toDecode)
          This function will decode a given string to it's decoded variant.
 byte[] decodeBytes(java.lang.String toDecode)
           
static byte[] decodeBytes(java.lang.String encoding, java.lang.String toDecode)
           
 java.lang.String encode(byte[] bytes)
          Encodes a byte array.
 java.lang.String encode(java.lang.String toEncode)
          This function will encode a given string to it's encoded variant.
static java.lang.String encode(java.lang.String encoding, byte[] bytes)
           
static java.lang.String encode(java.lang.String encoding, java.lang.String toEncode)
          This function will encode a given string to it's encoded variant.
 boolean isByteToCharEncoder()
          Checks if the transformations makes from byte[] String.
 boolean isCharEncoder()
          Checks if the transformation is between two Strings.
static boolean isEncoding(java.lang.String e)
          Checks if a certain string represents a known transformation.
static void main(java.lang.String[] argv)
          Invocation of the class from the commandline for testing.
static java.util.Set possibleEncodings()
          All the currently known encodings.
static void register(java.lang.String clazz)
          Add new transformation types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Encode

public Encode(java.lang.String encoding)
Created a encode instance of a certain type of encoding. It will instantiate the right class, and configure it. This instantion will be used when you call 'encode' or 'decode' members later.
Parameters:
encoding - a string that describes which encoding should be used.
Method Detail

register

public static void register(java.lang.String clazz)
Add new transformation types. Feed it with a class name (which must implement Transformer)
Parameters:
String - a class name.

encode

public static java.lang.String encode(java.lang.String encoding,
                                      java.lang.String toEncode)
This function will encode a given string to it's encoded variant. It is static, it will make a temporary instance of the Transformer class. If you need to encode alot, it is better to use new Encode first.
Parameters:
encoding - a string that describes which encoding should be used.
toEncode - a string which is the value which should be encoded. This can also be a byte[].
Returns:
a string which is the encoded representation of toEncode with the given encoding

encode

public static java.lang.String encode(java.lang.String encoding,
                                      byte[] bytes)

decode

public static java.lang.String decode(java.lang.String encoding,
                                      java.lang.String toDecode)
This function will decode a given string to it's decoded variant.
Parameters:
decoding - a string that describes which decoding should be used.
toDecode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding
See Also:
encode(java.lang.String, java.lang.String)

decodeBytes

public static byte[] decodeBytes(java.lang.String encoding,
                                 java.lang.String toDecode)

encode

public java.lang.String encode(java.lang.String toEncode)
This function will encode a given string to it's encoded variant.
Parameters:
toEncode - A string which is the value which should be encoded. If the transformer does transform bytes, then first getBytes is done on the String.
Returns:
a string which is the encoded representation of toEncode with the given encoding

encode

public java.lang.String encode(byte[] bytes)
Encodes a byte array.
Returns:
a string;;

decode

public java.lang.String decode(java.lang.String toDecode)
This function will decode a given string to it's decoded variant
Parameters:
toDecode - a string which is the value which should be encoded.
Returns:
a string which is the encoded representation of toEncode with the given encoding

decodeBytes

public byte[] decodeBytes(java.lang.String toDecode)

possibleEncodings

public static java.util.Set possibleEncodings()
All the currently known encodings.
Returns:
Set of Strings.

isEncoding

public static boolean isEncoding(java.lang.String e)
Checks if a certain string represents a known transformation.

isCharEncoder

public boolean isCharEncoder()
Checks if the transformation is between two Strings.

isByteToCharEncoder

public boolean isByteToCharEncoder()
Checks if the transformations makes from byte[] String.

main

public static void main(java.lang.String[] argv)
Invocation of the class from the commandline for testing.


MMBase 2002