Class ASCII85OutputStream

java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.jpedal.io.filter.ASCII85OutputStream
All Implemented Interfaces:
Closeable, Flushable, AutoCloseable

public class ASCII85OutputStream extends FilterOutputStream
An output stream that encodes bytes using the ASCII 85 filter

Encodes to ASCII characters ! (0x21) through u (0x75) and the character z (0x7A), with the 2-character sequence ~> 0x7E3E as the EOD marker.

Specifically, ASCII base-85 encoding shall produce 5 ASCII characters for every 4 bytes of binary data. Each group of 4 binary input bytes (b1, b2, b3, b4), shall be converted to a group of 5 output bytes (c1, c2, c3, c4, c5), using the relation:


  (b1 * 256^3) + (b2 * 256^2) + (b3 * 256) + b4
      = (c1 * 85^4) + (c2 * 85 ^ 3) + (c3 * 85^2) + (c4 * 85) + c5
 
In other words, 4 bytes of binary data shall be interpreted as a base-256 number and then shall be converted to a base-85 number. The five bytes of the base-85 number shall then be converted to ASCII characters by adding 33 (the ASCII code for the character !) to each. The resulting encoded data shall contain only printable ASCII characters with codes in the range 33 (!) to 117 (u). As a special case, if all five bytes are 0, they shall be represented by the character with code 122 (z) instead of by five exclamation points (!!!!!).

If the length of the data to be encoded is not a multiple of 4 bytes, the last, partial group of 4 shall be used to produce a last, partial group of 5 output characters. Given n (1, 2, or 3) bytes of binary data, the encoder shall first append 4 - n zero bytes to make a complete group of 4. It shall encode this group in the usual way, but shall not apply the special z case. Finally, it shall write only the first n + 1 characters of the resulting group of 5. These characters shall be immediately followed by the ~> EOD marker.
- PDF Spec ISO 32000-2