edu.neu.ccs.codec
Class EscapedCodec

java.lang.Object
  extended byedu.neu.ccs.codec.EscapedCodec
All Implemented Interfaces:
Codec, Serializable

public final class EscapedCodec
extends Object
implements Codec, Serializable

CODEC implementation whose encoding scheme uses separator sequences to separate distinct data elements and uses escape sequences to mask separator sequences and escape sequences at each level of recursion. This CODEC does not make use of data compression, and does not result in any data loss. This CODEC produces encoded data that is extremely readable at low levels of recursion, but is very difficult to read at high levels of recursion.

The unique three letter identifier for this CODEC is "ESC". This CODEC is automatically installed by the JPT.

Since:
1.0
Version:
2.2
See Also:
CodecUtilities, Serialized Form

Field Summary
private static String ESCAPE
          The sequence of characters that escapes the following character or sequence from being considered an escape or separator sequence.
private static String NULL
          The sequence of characters that represents null, or "no data".
private static String SEPARATOR
          The sequence of characters that separates elements of an encoded String.
 
Constructor Summary
EscapedCodec()
          Constructs an object capable of encoding and decoding data using the "Escaped-separated" encoding scheme.
 
Method Summary
 String[] decode(String data)
          Decodes the given compound data String into an array of data Strings using the "Escaped-separated" encoding scheme.
 String encode(String[] data)
          Encodes the given array of data Strings into a single compound data String using the "Escaped-separated" encoding scheme.
private  String escape(String data)
          Prepares an individual element from the array of String data for encoding by preceding each separator and escape sequence with an escape sequence.
 String getPrefix()
          Returns the unique identifier for this encoding scheme: the String "ESC".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

private static final String SEPARATOR
The sequence of characters that separates elements of an encoded String.

See Also:
Constant Field Values

ESCAPE

private static final String ESCAPE
The sequence of characters that escapes the following character or sequence from being considered an escape or separator sequence.

See Also:
Constant Field Values

NULL

private static final String NULL
The sequence of characters that represents null, or "no data".

See Also:
Constant Field Values
Constructor Detail

EscapedCodec

public EscapedCodec()
Constructs an object capable of encoding and decoding data using the "Escaped-separated" encoding scheme.

Method Detail

encode

public String encode(String[] data)
Encodes the given array of data Strings into a single compound data String using the "Escaped-separated" encoding scheme. If the given array is null, a representation of null is returned.

Specified by:
encode in interface Codec
Parameters:
data - an array of data Strings
Returns:
the resulting encoded String
See Also:
decode(String), CodecUtilities.encode(String[]), CodecUtilities.encode(Stringable[]), Codec

decode

public String[] decode(String data)
                throws ParseException
Decodes the given compound data String into an array of data Strings using the "Escaped-separated" encoding scheme. If the given data is null or the representation of null, this method returns null.

Specified by:
decode in interface Codec
Parameters:
data - an encoded data String
Returns:
the resulting array of data Strings
Throws:
ParseException - if the data was not encoded using this scheme
See Also:
encode(String[]), CodecUtilities.decode(String), Codec

getPrefix

public String getPrefix()
Returns the unique identifier for this encoding scheme: the String "ESC".

Specified by:
getPrefix in interface Codec
See Also:
CodecUtilities.installCodec(Codec), CodecUtilities.getDefaultCodec(), Codec

escape

private String escape(String data)
Prepares an individual element from the array of String data for encoding by preceding each separator and escape sequence with an escape sequence. If the given data is null, the representation for null data is returned.

Parameters:
data - the data String to escape
Returns:
the escaped data String
See Also:
encode(String[])