JSS 3.1.2

org.mozilla.jss.util
Class Base64OutputStream

java.lang.Object
  |
  +--java.io.OutputStream
        |
        +--java.io.FilterOutputStream
              |
              +--org.mozilla.jss.util.Base64OutputStream

public class Base64OutputStream
extends java.io.FilterOutputStream

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
private  short charsOnLine
           
private  int charsPerLine
           
private static int DEFAULT_QUADS_PER_LINE
           
private  boolean doLineBreaks
           
private static char[] encoding
           
private  byte[] input
           
private  short inputCount
           
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
Base64OutputStream(java.io.PrintStream out)
          Create a stream that does not insert line breaks.
Base64OutputStream(java.io.PrintStream out, int quadsPerLine)
           
 
Method Summary
 void close()
          This flushes the stream and closes the next stream downstream.
 void flush()
          Calling this will put the ending padding on the base64 stream, so don't call it until you have no data left.
private  void outputOneAtom()
          Output 3 bytes of input as 4 bytes of base-64 encoded output.
 void write(byte[] buffer)
           
 void write(byte[] buffer, int offset, int count)
           
 void write(int oneByte)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

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

doLineBreaks

private boolean doLineBreaks
Constructor Detail

Base64OutputStream

public Base64OutputStream(java.io.PrintStream out)
Create a stream that does not insert line breaks. To have line breaks, use the other constructor.

Base64OutputStream

public Base64OutputStream(java.io.PrintStream out,
                          int quadsPerLine)
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 Detail

write

public void write(int oneByte)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

close

public void close()
           throws java.io.IOException
This flushes the stream and closes the next stream downstream.
Overrides:
close in class java.io.FilterOutputStream

flush

public void flush()
           throws java.io.IOException
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.
Overrides:
flush in class java.io.FilterOutputStream

write

public void write(byte[] buffer)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

write

public void write(byte[] buffer,
                  int offset,
                  int count)
           throws java.io.IOException
Overrides:
write in class java.io.FilterOutputStream

outputOneAtom

private void outputOneAtom()
                    throws java.io.IOException
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.

JSS 3.1.2