public class

UCDecoder

extends CharacterDecoder
java.lang.Object
   ↳ sun.misc.CharacterDecoder
     ↳ sun.misc.UCDecoder

Class Overview

This class implements a robust character decoder. The decoder will converted encoded text into binary data. 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.
 
If an error is encountered during decoding this class throws a CEFormatException. The specific detail messages are:
    "UCDecoder: High byte parity error."
    "UCDecoder: Low byte parity error."
    "UCDecoder: Out of sequence line."
    "UCDecoder: CRC check failed."
 

Summary

Public Constructors
UCDecoder()
Protected Methods
int bytesPerAtom()
This class encodes two bytes per atom.
int bytesPerLine()
this class encodes 48 bytes per line
void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int l)
Decode one atom - reads the characters from the input stream, decodes them, and checks for valid parity.
void decodeBufferPrefix(PushbackInputStream inStream, OutputStream outStream)
decodeBufferPrefix initializes the sequence number to zero.
int decodeLinePrefix(PushbackInputStream inStream, OutputStream outStream)
decodeLinePrefix reads the sequence number and the number of encoded bytes from the line.
void decodeLineSuffix(PushbackInputStream inStream, OutputStream outStream)
this method reads the CRC that is at the end of every line and verifies that it matches the computed CRC.
[Expand]
Inherited Methods
From class sun.misc.CharacterDecoder
From class java.lang.Object

Public Constructors

public UCDecoder ()

Protected Methods

protected int bytesPerAtom ()

This class encodes two bytes per atom.

protected int bytesPerLine ()

this class encodes 48 bytes per line

protected void decodeAtom (PushbackInputStream inStream, OutputStream outStream, int l)

Decode one atom - reads the characters from the input stream, decodes them, and checks for valid parity.

Throws
IOException

protected void decodeBufferPrefix (PushbackInputStream inStream, OutputStream outStream)

decodeBufferPrefix initializes the sequence number to zero.

protected int decodeLinePrefix (PushbackInputStream inStream, OutputStream outStream)

decodeLinePrefix reads the sequence number and the number of encoded bytes from the line. If the sequence number is not the previous sequence number + 1 then an exception is thrown. UCE lines are line terminator immune, they all start with * so the other thing this method does is scan for the next line by looking for the * character.

Throws
CEFormatException out of sequence lines detected.
IOException

protected void decodeLineSuffix (PushbackInputStream inStream, OutputStream outStream)

this method reads the CRC that is at the end of every line and verifies that it matches the computed CRC.

Throws
CEFormatException if CRC check fails.
IOException