Class Overview
This class implements a robust character encoder. The encoder is designed
to convert binary data into printable characters. The characters are
assumed to exist but they are not assumed to be ASCII, the complete set
is 0-9, A-Z, a-z, "(", and ")".
The basic encoding unit is a 3 character atom. It encodes two bytes
of data. Bytes are encoded into a 64 character set, the characters
were chosen specifically because they appear in all codesets.
We don't care what their numerical equivalent is because
we use a character array to map them. This is like UUencoding
with the dependency on ASCII removed.
The three chars that make up an atom are encoded as follows:
00xxxyyy 00axxxxx 00byyyyy
00 = leading zeros, all values are 0 - 63
xxxyyy - Top 3 bits of X, Top 3 bits of Y
axxxxx - a = X parity bit, xxxxx lower 5 bits of X
byyyyy - b = Y parity bit, yyyyy lower 5 bits of Y
The atoms are arranged into lines suitable for inclusion into an
email message or text file. The number of bytes that are encoded
per line is 48 which keeps the total line length under 80 chars)
Each line has the form(
*(LLSS)(DDDD)(DDDD)(DDDD)...(CRC)
Where each (xxx) represents a three character atom.
(LLSS) - 8 bit length (high byte), and sequence number
modulo 256;
(DDDD) - Data byte atoms, if length is odd, last data
atom has (DD00) (high byte data, low byte 0)
(CRC) - 16 bit CRC for the line, includes length,
sequence, and all data bytes. If there is a
zero pad byte (odd length) it is _NOT_
included in the CRC.
Summary
Protected Methods |
int
|
bytesPerAtom()
this clase encodes two bytes per atom
|
int
|
bytesPerLine()
this class encodes 48 bytes per line
|
void
|
encodeAtom(OutputStream outStream, byte[] data, int offset, int len)
encodeAtom - take two bytes and encode them into the correct
three characters.
|
void
|
encodeBufferPrefix(OutputStream a)
The buffer prefix code is used to initialize the sequence number
to zero.
|
void
|
encodeLinePrefix(OutputStream outStream, int length)
Each UCE encoded line starts with a prefix of '*[XXX]', where
the sequence number and the length are encoded in the first
atom.
|
void
|
encodeLineSuffix(OutputStream outStream)
each UCE encoded line ends with YYY and encoded version of the
16 bit checksum.
|
[Expand]
Inherited Methods |
From class
sun.misc.CharacterEncoder
abstract
int
|
bytesPerAtom()
Return the number of bytes per atom of encoding
|
abstract
int
|
bytesPerLine()
Return the number of bytes that can be encoded per line
|
void
|
encode(byte[] aBuffer, OutputStream aStream)
Encode the buffer in aBuffer and write the encoded
result to the OutputStream aStream.
|
String
|
encode(ByteBuffer aBuffer)
A 'streamless' version of encode that simply takes a ByteBuffer
and returns a string containing the encoded buffer.
|
void
|
encode(InputStream inStream, OutputStream outStream)
Encode bytes from the input stream, and write them as text characters
to the output stream.
|
String
|
encode(byte[] aBuffer)
A 'streamless' version of encode that simply takes a buffer of
bytes and returns a string containing the encoded buffer.
|
void
|
encode(ByteBuffer aBuffer, OutputStream aStream)
Encode the aBuffer ByteBuffer and write the encoded
result to the OutputStream aStream.
|
abstract
void
|
encodeAtom(OutputStream aStream, byte[] someBytes, int anOffset, int aLength)
Encode one "atom" of information into characters.
|
void
|
encodeBuffer(byte[] aBuffer, OutputStream aStream)
Encode the buffer in aBuffer and write the encoded
result to the OutputStream aStream.
|
String
|
encodeBuffer(ByteBuffer aBuffer)
A 'streamless' version of encode that simply takes a ByteBuffer
and returns a string containing the encoded buffer.
|
void
|
encodeBuffer(InputStream inStream, OutputStream outStream)
Encode bytes from the input stream, and write them as text characters
to the output stream.
|
void
|
encodeBuffer(ByteBuffer aBuffer, OutputStream aStream)
Encode the aBuffer ByteBuffer and write the encoded
result to the OutputStream aStream.
|
String
|
encodeBuffer(byte[] aBuffer)
A 'streamless' version of encode that simply takes a buffer of
bytes and returns a string containing the encoded buffer.
|
void
|
encodeBufferPrefix(OutputStream aStream)
Encode the prefix for the entire buffer.
|
void
|
encodeBufferSuffix(OutputStream aStream)
Encode the suffix for the entire buffer.
|
void
|
encodeLinePrefix(OutputStream aStream, int aLength)
Encode the prefix that starts every output line.
|
void
|
encodeLineSuffix(OutputStream aStream)
Encode the suffix that ends every output line.
|
int
|
readFully(InputStream in, byte[] buffer)
This method works around the bizarre semantics of BufferedInputStream's
read method.
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait()
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object.
|
final
void
|
wait(long timeout, int nanos)
Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.
|
final
void
|
wait(long timeout)
Causes the current thread to wait until either another thread invokes the
notify() method or the
notifyAll() method for this object, or a
specified amount of time has elapsed.
|
|
Public Constructors
Protected Methods
protected
int
bytesPerAtom
()
this clase encodes two bytes per atom
protected
int
bytesPerLine
()
this class encodes 48 bytes per line
protected
void
encodeAtom
(OutputStream outStream, byte[] data, int offset, int len)
encodeAtom - take two bytes and encode them into the correct
three characters. If only one byte is to be encoded, the other
must be zero. The padding byte is not included in the CRC computation.
protected
void
encodeBufferPrefix
(OutputStream a)
The buffer prefix code is used to initialize the sequence number
to zero.
protected
void
encodeLinePrefix
(OutputStream outStream, int length)
Each UCE encoded line starts with a prefix of '*[XXX]', where
the sequence number and the length are encoded in the first
atom.
protected
void
encodeLineSuffix
(OutputStream outStream)
each UCE encoded line ends with YYY and encoded version of the
16 bit checksum. The most significant byte of the check sum
is always encoded FIRST.