edu.harvard.deas.hyperenc.util
Class UUCoder

java.lang.Object
  extended by edu.harvard.deas.hyperenc.util.UUCoder

public class UUCoder
extends Object

Encodes and decodes binary data into ASCII using a similar, but not identical, format to UUEncoding.

Bytes are translated into ASCII characters in the same way as UUEncoding: groups of three 8-bit bytes are realigned into sets of four 6-bit groups. Each 6-bit group is then converted to an ASCII character by adding 32, with the exception of 00: a zero is represented by the backtick (`, ASCII 96). Thus the valid characters, spanning from ASCII 33 to ASCII 96, are:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
 
If the message to be encoded is not a multiple of 3 bytes, it is padded with zeros so that it is.

Messages are not delineated as in standard UUEncoding. The first line of a message is a decimal number indicating how many bytes are encoded by the message. This is followed by the encoded data on as many lines as needed. Unlike standard UUEncoding, the length of each line is not indicated in any way. The only requirement is that each line contain a multiple of 4 characters, not including the trailing newline character(s). Finally, the message ends with a line consisting of only the token "TERMEND".


Field Summary
static String TERMINATOR
          Token that indicates the end of a message.
 
Constructor Summary
UUCoder()
           
 
Method Summary
static byte[] decode(String data)
          Decodes the given string.
static String encode(byte[] data)
          Encodes the given data.
static String getLegalChars()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TERMINATOR

public static final String TERMINATOR
Token that indicates the end of a message.

See Also:
Constant Field Values
Constructor Detail

UUCoder

public UUCoder()
Method Detail

getLegalChars

public static String getLegalChars()
Returns:
a String containing all the legal characters that may appear in an encoding (excluding newline characters)

encode

public static String encode(byte[] data)
Encodes the given data. The format of the encoding is described in the class description.

Parameters:
data - the data to be encoded
Returns:
a string containing the encoding of data. The string contains only ASCII characters from 33 to 96.

decode

public static byte[] decode(String data)
Decodes the given string. The format of the encoding is described in the class description.

Parameters:
data - the data to be decoded
Returns:
a byte array containing the data encoded by data
Throws:
IllegalArgumentException - if data is not a valid encoding