Package com.orsonpdf.filter
Class Ascii85OutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
com.orsonpdf.filter.Ascii85OutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
An ascii85 encoder, implemented as an OutputStream.
Call flush() or close() to properly close the
ascii85 block. The block must be closed for the encoded data to be valid.
Do not call flush() before you intend to end the ascii85 block.
Multiple ascii85 blocks may be encoded by calling flush() and then writing
more bytes to the stream.
Note that if you use the constructor with the
useSpaceCompression option, the encoded text will be shorter
when there are many consecutive space characters in the encoded data, but
it will not be compatible with Adobe's ascii85 implementation. It makes sense
to use this option if interoperability with other ascii85 implementations
is not a requirement.
- Author:
- Ben Upsavs
-
Field Summary
Fields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreates an output stream to encode ascii85 data, using a default line with of 72 characters and not using the space character compression option.Ascii85OutputStream(OutputStream out, boolean useSpaceCompression) Creates an output stream to encode ascii85 data, using a default line width of 72 characters.Ascii85OutputStream(OutputStream out, int width, boolean useSpaceCompression) Creates an output stream to encode ascii85 data. -
Method Summary
Modifier and TypeMethodDescriptionvoidflush()Adds the closing block and flushes the underlying output stream.voidwrite(int b) Writes a single byte to the stream.voidwriteUnencoded(byte[] b) Writes bytes to the underlying output stream, unencoded.voidwriteUnencoded(byte[] b, int off, int len) Writes bytes to the underlying output stream, unencoded.voidwriteUnencoded(int b) Writes a single byte to the underlying output stream, unencoded.Methods inherited from class java.io.FilterOutputStream
close, write, writeMethods inherited from class java.io.OutputStream
nullOutputStream
-
Constructor Details
-
Ascii85OutputStream
Creates an output stream to encode ascii85 data, using a default line with of 72 characters and not using the space character compression option. Callflush()to add the padding and end the ascii85 block.- Parameters:
out- the output stream.
-
Ascii85OutputStream
Creates an output stream to encode ascii85 data, using a default line width of 72 characters. Callflush()to end the ascii85 block.- Parameters:
out- the output stream.useSpaceCompression- Whether to use space character compression in the output.
-
Ascii85OutputStream
Creates an output stream to encode ascii85 data. Callflush()to end the ascii85 block.- Parameters:
out- the output stream.width- The maximum line width of the encoded output text. Whitespace characters are ignored when decoding.useSpaceCompression- Whether to use space character compression in the output.
-
-
Method Details
-
write
Writes a single byte to the stream. SeeOutputStream.write(int b)for details.- Overrides:
writein classFilterOutputStream- Parameters:
b- The byte to encode.- Throws:
IOException- If an I/O error occurs in the underlying output stream.
-
writeUnencoded
Writes a single byte to the underlying output stream, unencoded. If done improperly, this may corrupt the ascii85 data stream. Writing a byte using this method may cause the line length to increase since the line length counter will not be updated by this method.- Parameters:
b- The byte to write.- Throws:
IOException- If the underlying output stream has an I/O error.
-
writeUnencoded
Writes bytes to the underlying output stream, unencoded. If done improperly, this may corrupt the ascii85 data stream. Writing bytes using this method may cause the line length to increase since the line length counter will not be updated by this method.- Parameters:
b- The bytes to write.- Throws:
IOException- If the underlying output stream has an I/O error.
-
writeUnencoded
Writes bytes to the underlying output stream, unencoded. If done improperly, this may corrupt the ascii85 data stream. Writing bytes using this method may cause the line length to increase since the line length counter will not be updated by this method.- Parameters:
b- The bytes to write.off- The offset ofbto start reading from.len- The amount of bytes to read fromb.- Throws:
IOException- If the underlying output stream has an I/O error.
-
flush
Adds the closing block and flushes the underlying output stream. This method should only be called if it is intended that the ascii85 block should be closed.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-