Package org.mozilla.jss.util
Class Base64OutputStream
java.lang.Object
java.io.OutputStream
java.io.FilterOutputStream
org.mozilla.jss.util.Base64OutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
An output stream filter that takes arbitrary bytes and outputs their
base64 encoding. Call flush() or close() to write out the final padding.
The class also automatically puts line breaks in the output stream.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate shortprivate intprivate static final intprivate booleanprivate static final char[]private byte[]private shortFields inherited from class java.io.FilterOutputStream
out -
Constructor Summary
ConstructorsConstructorDescriptionCreate a stream that does not insert line breaks.Base64OutputStream(PrintStream out, int quadsPerLine) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()This flushes the stream and closes the next stream downstream.voidflush()Calling this will put the ending padding on the base64 stream, so don't call it until you have no data left.private voidOutput 3 bytes of input as 4 bytes of base-64 encoded output.voidwrite(byte[] buffer) voidwrite(byte[] buffer, int offset, int count) voidwrite(int oneByte) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
encoding
private static final char[] encoding -
input
private byte[] input -
inputCount
private short inputCount -
charsOnLine
private short charsOnLine -
charsPerLine
private int charsPerLine -
DEFAULT_QUADS_PER_LINE
private static final int DEFAULT_QUADS_PER_LINE- See Also:
-
doLineBreaks
private boolean doLineBreaks
-
-
Constructor Details
-
Base64OutputStream
Create a stream that does not insert line breaks. To have line breaks, use the other constructor. -
Base64OutputStream
- Parameters:
quadsPerLine- Number of 4-character blocks to write before outputting a line break. For example, for 76-characters per line, pass in 76/4 = 19.
-
-
Method Details
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
close
This flushes the stream and closes the next stream downstream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterOutputStream- Throws:
IOException
-
flush
Calling this will put the ending padding on the base64 stream, so don't call it until you have no data left. The class does no unnecessary buffering, so you probably shouldn't call it at all.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
write
- Overrides:
writein classFilterOutputStream- Throws:
IOException
-
outputOneAtom
Output 3 bytes of input as 4 bytes of base-64 encoded output. If there are fewer than 3 bytes available, the output will be padded according to the spec. Padding should only happen at the end of the stream.- Throws:
IOException
-