java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.jfree.pdf.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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
private boolean
private int
private int
private boolean
private int
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 TypeMethodDescriptionprivate void
encode
(int tuple, int count) Encodestuple
and writes it to the output stream.void
flush()
Adds the closing block and flushes the underlying output stream.private void
void
write
(int b) Writes a single byte to the stream.void
writeUnencoded
(byte[] b) Writes bytes to the underlying output stream, unencoded.void
writeUnencoded
(byte[] b, int off, int len) Writes bytes to the underlying output stream, unencoded.void
writeUnencoded
(int b) Writes a single byte to the underlying output stream, unencoded.Methods inherited from class java.io.FilterOutputStream
close, write, write
Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
width
private int width -
pos
private int pos -
tuple
private int tuple -
count
private int count -
encoding
private boolean encoding -
useSpaceCompression
private boolean useSpaceCompression
-
-
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
-
startEncoding
- Throws:
IOException
-
write
Writes a single byte to the stream. SeeOutputStream.write(int b)
for details.- Overrides:
write
in 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 ofb
to start reading from.len
- The amount of bytes to read fromb
.- Throws:
IOException
- If the underlying output stream has an I/O error.
-
encode
Encodestuple
and writes it to the output stream. The number of bytes in the tuple, and thus the value ofcount
is normally 4, however less bytes may also be encoded, particularly if the input stream has ended before the current tuple is full.- Parameters:
tuple
- The tuple to encode.count
- The number of bytes stuffed into the tuple.- Throws:
IOException
- If an I/O error occurs.
-
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:
flush
in interfaceFlushable
- Overrides:
flush
in classFilterOutputStream
- Throws:
IOException
-