Package com.orsonpdf.filter
Class Ascii85OutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- com.orsonpdf.filter.Ascii85OutputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.AutoCloseable
public class Ascii85OutputStream extends java.io.FilterOutputStream
An ascii85 encoder, implemented as an
OutputStream
.Call
flush()
orclose()
to properly close the ascii85 block. The block must be closed for the encoded data to be valid. Do not callflush()
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.
-
-
Constructor Summary
Constructors Constructor Description Ascii85OutputStream(java.io.OutputStream out)
Creates an output stream to encode ascii85 data, using a default line with of 72 characters and not using the space character compression option.Ascii85OutputStream(java.io.OutputStream out, boolean useSpaceCompression)
Creates an output stream to encode ascii85 data, using a default line width of 72 characters.Ascii85OutputStream(java.io.OutputStream out, int width, boolean useSpaceCompression)
Creates an output stream to encode ascii85 data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private 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
startEncoding()
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.
-
-
-
Constructor Detail
-
Ascii85OutputStream
public Ascii85OutputStream(java.io.OutputStream out)
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
public Ascii85OutputStream(java.io.OutputStream out, boolean useSpaceCompression)
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
public Ascii85OutputStream(java.io.OutputStream out, int width, boolean useSpaceCompression)
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 Detail
-
startEncoding
private void startEncoding() throws java.io.IOException
- Throws:
java.io.IOException
-
write
public void write(int b) throws java.io.IOException
Writes a single byte to the stream. SeeOutputStream.write(int b)
for details.- Overrides:
write
in classjava.io.FilterOutputStream
- Parameters:
b
- The byte to encode.- Throws:
java.io.IOException
- If an I/O error occurs in the underlying output stream.
-
writeUnencoded
public void writeUnencoded(int b) throws java.io.IOException
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:
java.io.IOException
- If the underlying output stream has an I/O error.
-
writeUnencoded
public void writeUnencoded(byte[] b) throws java.io.IOException
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:
java.io.IOException
- If the underlying output stream has an I/O error.
-
writeUnencoded
public void writeUnencoded(byte[] b, int off, int len) throws java.io.IOException
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:
java.io.IOException
- If the underlying output stream has an I/O error.
-
encode
private void encode(int tuple, int count) throws java.io.IOException
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:
java.io.IOException
- If an I/O error occurs.
-
flush
public void flush() throws java.io.IOException
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 interfacejava.io.Flushable
- Overrides:
flush
in classjava.io.FilterOutputStream
- Throws:
java.io.IOException
-
-