edu.neu.ccs.codec
Class CodecUtilities

java.lang.Object
  extended byedu.neu.ccs.codec.CodecUtilities

public class CodecUtilities
extends Object

Contains utility methods providing CODEC operations.

Nonstandard CODECs, that is, CODECs that are not included in the JPT, must be installed using the installCodec method of this class.

Encoding and decoding operations must be performed through the methods of this class, and not directly through the methods of an instance of any particular CODEC.

The only change in 2.4.0 is to the documentation of the method decode. All code in this class is the same as before.

Version:
2.4.0
See Also:
Codec

Field Summary
private static Hashtable codecs
          The table of installed codecs.
 
Constructor Summary
CodecUtilities()
           
 
Method Summary
private static boolean areCodecsInstalled()
          Returns whether or not the standard CODECs have been installed.
static String[] decode(String data)
          Decodes the given encoded data String into its (possibly encoded) component parts, using the CODEC identified within the data by its unique prefix.
static String encode(String[] data)
          Encodes the given array of (possibly encoded) data Strings into a single encoded data String using the default CODEC.
static String encode(String[] data, String codecID)
          Encodes the given array of (possibly encoded) data Strings into a single encoded data String using the installed CODEC with the given unique identifier.
static String encode(Stringable[] data)
          Encodes the given array of Stringable objects into an encoded data String using the default CODEC.
static String encode(Stringable[] data, String codecID)
          Encodes the given array of Stringable objects into a single encoded data String using the installed CODEC with the given unique identifier.
static String getDefaultCodec()
          Returns the unique identifier for the default installed CODEC.
static void installCodec(Codec c)
          Installs the given CODEC in the table of available CODECs.
private static void installStandardCodecs()
          Installs the standard CODECs for the JPT.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

codecs

private static Hashtable codecs
The table of installed codecs.

Constructor Detail

CodecUtilities

public CodecUtilities()
Method Detail

decode

public static String[] decode(String data)

Decodes the given encoded data String into its (possibly encoded) component parts, using the CODEC identified within the data by its unique prefix.

Throws JPTError if an error occurs. Class JPTError extends the Java class Error which implements the interface Throwable.

As of 2.4.0, this method is called by the method Strings.decode which rather than throw an error, returns a null array in case of an error. It is recommended that this method be called directly only if the caller specifically wants to know what specific JPTError may have occured in an error situation. The method Strings.decode is definitely easier to use.

Parameters:
data - a data String to be decoded
Returns:
the resulting array of Strings
Since:
1.0
See Also:
encode(String[]), encode(String[], String), encode(Stringable[]), encode(Stringable[], String)

encode

public static String encode(String[] data)
Encodes the given array of (possibly encoded) data Strings into a single encoded data String using the default CODEC.

Parameters:
data - an array of data Strings to be encoded
Returns:
the encoded data String
Since:
1.0
See Also:
decode(String), encode(String[], String), encode(Stringable[]), encode(Stringable[], String)

encode

public static String encode(String[] data,
                            String codecID)
Encodes the given array of (possibly encoded) data Strings into a single encoded data String using the installed CODEC with the given unique identifier.

Parameters:
data - an array of data Strings to be encoded
codecID - the unique identifier for the desired CODEC
Returns:
the resulting encoded data String
Since:
1.0
See Also:
decode(String), encode(String[]), encode(Stringable[]), encode(Stringable[], String)

encode

public static String encode(Stringable[] data)
Encodes the given array of Stringable objects into an encoded data String using the default CODEC.

Parameters:
data - an array of objects to be encoded
Returns:
the resulting encoded data String
Since:
1.0
See Also:
decode(String), encode(String[]), encode(String[], String), encode(Stringable[], String)

encode

public static String encode(Stringable[] data,
                            String codecID)
Encodes the given array of Stringable objects into a single encoded data String using the installed CODEC with the given unique identifier.

Parameters:
data - an array of objects to be encoded
codecID - the unique identifier for the desired CODEC
Returns:
the resulting encoded data String
Since:
1.0
See Also:
decode(String), encode(String[]), encode(String[], String), encode(Stringable[])

getDefaultCodec

public static String getDefaultCodec()
Returns the unique identifier for the default installed CODEC.

Since:
1.0
See Also:
encode(String[], String), encode(Stringable[], String)

installCodec

public static void installCodec(Codec c)
Installs the given CODEC in the table of available CODECs.

Parameters:
c - the desired CODEC object to install
Since:
1.0

areCodecsInstalled

private static boolean areCodecsInstalled()
Returns whether or not the standard CODECs have been installed.

Since:
1.0
See Also:
installStandardCodecs()

installStandardCodecs

private static void installStandardCodecs()
Installs the standard CODECs for the JPT.

Since:
1.0
See Also:
areCodecsInstalled()