Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


com.tangosol.io
Class Base64OutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.tangosol.io.Base64OutputStream

All Implemented Interfaces:
OutputStreaming, java.io.Closeable, java.io.Flushable

public class Base64OutputStream
extends java.io.OutputStream
implements OutputStreaming

Writes binary data into a Writer using IETF RFC 2045 Base64 Content Transfer Encoding. If the Base64OutputStream is not the first to write data into the Writer, it may be desired to write a line feed before Base64 data. According to the specification, Base64 data cannot exceed 76 characters per line. Be careful to avoid calling flush() except when a stream of Base64 content is complete.

Author:
cp 2000.09.06

Field Summary
protected static char[] BASE64_ALPHABET
          Base64 encodes into this "alphabet" of 64 characters.
protected static char BASE64_LF
          The Base64 line feed character.
protected static char BASE64_PAD
          The Base64 padding character.
protected static int GROUPS_PER_LINE
          The number of Base64 character groups in one line.
protected  byte[] m_abAccum
          Accumulated bytes.
protected  char[] m_achGroup
          An array that is used to send 4 characters at a time to the underlying Writer object.
protected  int m_cAccum
          The number of bytes accumulated (0, 1, 2 or 3).
protected  int m_cLineGroups
          The number of groups left to write in the current line.
protected  boolean m_fBreakLines
          True if lines are to be broken by BASE64_LF;
protected  boolean m_fClosed
          True after close is invoked.
protected  java.io.Writer m_writer
          The Writer object to which the Base64 encoded data is written.

 

Constructor Summary
Base64OutputStream(java.io.Writer writer)
          Construct a Base64OutputStream on a Writer object.
Base64OutputStream(java.io.Writer writer, boolean fBreakLines)
          Construct a Base64OutputStream on a Writer object and specifying a line-break option.

 

Method Summary
 void close()
          Close the stream, flushing any accumulated bytes.
static char[] encode(byte[] ab)
          Encode the passed binary data using Base64 encoding.
static char[] encode(byte[] ab, boolean fBreakLines)
          Encode the passed binary data using Base64 encoding.
static char[] encode(byte[] ab, int ofb, int cb, boolean fBreakLines)
          Encode the passed binary data using Base64 encoding.
 void flush()
          Close the stream, flushing any accumulated bytes.
protected  void flushAccumulator()
          Flushes the bytes accumulated by the write(int) method.
 void write(byte[] ab, int ofb, int cb)
          Writes len bytes from the specified byte array starting at offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.

 

Methods inherited from class java.io.OutputStream
write

 

Methods inherited from interface com.tangosol.io.OutputStreaming
write

 

Field Detail

BASE64_ALPHABET

protected static final char[] BASE64_ALPHABET
Base64 encodes into this "alphabet" of 64 characters.

BASE64_PAD

protected static final char BASE64_PAD
The Base64 padding character. Base64 is encoded into 4-character chunks; if the last chunk does not contain 4 characters, it is filled with this padding character.
See Also:
Constant Field Values

BASE64_LF

protected static final char BASE64_LF
The Base64 line feed character. Base64 is encoded into 76-character lines unless .
See Also:
Constant Field Values

GROUPS_PER_LINE

protected static final int GROUPS_PER_LINE
The number of Base64 character groups in one line. This number prevents a line from exceeding 76 characters.
See Also:
Constant Field Values

m_fClosed

protected boolean m_fClosed
True after close is invoked.

m_writer

protected java.io.Writer m_writer
The Writer object to which the Base64 encoded data is written.

m_fBreakLines

protected boolean m_fBreakLines
True if lines are to be broken by BASE64_LF;

m_cLineGroups

protected int m_cLineGroups
The number of groups left to write in the current line.

m_abAccum

protected byte[] m_abAccum
Accumulated bytes.

m_cAccum

protected int m_cAccum
The number of bytes accumulated (0, 1, 2 or 3).

m_achGroup

protected char[] m_achGroup
An array that is used to send 4 characters at a time to the underlying Writer object.

Constructor Detail

Base64OutputStream

public Base64OutputStream(java.io.Writer writer)
Construct a Base64OutputStream on a Writer object.
Parameters:
writer - the Writer to write the Base64 encoded data to

Base64OutputStream

public Base64OutputStream(java.io.Writer writer,
                          boolean fBreakLines)
Construct a Base64OutputStream on a Writer object and specifying a line-break option.
Parameters:
writer - the Writer to write the Base64 encoded data to
fBreakLines - true to break the output into 76-character lines

Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream.
Specified by:
write in interface OutputStreaming
Specified by:
write in class java.io.OutputStream
Parameters:
b - the byte.
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException may be thrown if the output stream has been closed.

write

public void write(byte[] ab,
                  int ofb,
                  int cb)
           throws java.io.IOException
Writes len bytes from the specified byte array starting at offset off to this output stream.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

Specified by:
write in interface OutputStreaming
Overrides:
write in class java.io.OutputStream
Parameters:
ab - the data
ofb - the start offset in the data
cb - the number of bytes to write
Throws:
java.io.IOException - if an I/O error occurs. In particular, an IOException is thrown if the output stream is closed.

flush

public void flush()
           throws java.io.IOException
Close the stream, flushing any accumulated bytes. The underlying writer is not closed.
Specified by:
flush in interface OutputStreaming
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs

close

public void close()
           throws java.io.IOException
Close the stream, flushing any accumulated bytes. The underlying writer is not closed.
Specified by:
close in interface OutputStreaming
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException - if an I/O error occurs

flushAccumulator

protected void flushAccumulator()
                         throws java.io.IOException
Flushes the bytes accumulated by the write(int) method.
Throws:
java.io.IOException - if an I/O error occurs

encode

public static char[] encode(byte[] ab)
Encode the passed binary data using Base64 encoding.
Parameters:
ab - the array containing the bytes to encode
Returns:
the encoded data as a char array

encode

public static char[] encode(byte[] ab,
                            boolean fBreakLines)
Encode the passed binary data using Base64 encoding.
Parameters:
ab - the array containing the bytes to encode
fBreakLines - true to break the output into 76-character lines
Returns:
the encoded data as a char array

encode

public static char[] encode(byte[] ab,
                            int ofb,
                            int cb,
                            boolean fBreakLines)
Encode the passed binary data using Base64 encoding.
Parameters:
ab - the array containing the bytes to encode
ofb - the start offset in the byte array
cb - the number of bytes to encode
fBreakLines - true to break the output into 76-character lines
Returns:
the encoded data as a char array

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.1.0

E22843-01


Copyright © 2000, 2011, Oracle and/or its affiliates. All rights reserved.