public class

BASE64EncoderStream

extends FilterOutputStream
java.lang.Object
   ↳ java.io.OutputStream
     ↳ java.io.FilterOutputStream
       ↳ com.google.code.com.sun.mail.util.BASE64EncoderStream
Known Direct Subclasses

Class Overview

This class implements a BASE64 encoder. It is implemented as a FilterOutputStream, so one can just wrap this class around any output stream and write bytes into this filter. The encoding is done as the bytes are written out.

Summary

Fields
private byte[] buffer
private int bufsize
private int bytesPerLine
private int count
private int lineLimit
private static byte[] newline
private boolean noCRLF
private byte[] outbuf
private static final char[] pem_array This array maps the characters to their 6 bit values
[Expand]
Inherited Fields
From class java.io.FilterOutputStream
Public Constructors
BASE64EncoderStream(OutputStream out, int bytesPerLine)
Create a BASE64 encoder that encodes the specified output stream.
BASE64EncoderStream(OutputStream out)
Create a BASE64 encoder that encodes the specified input stream.
Public Methods
synchronized void close()
Forces any buffered output bytes to be encoded out to the stream and closes this output stream
static byte[] encode(byte[] inbuf)
Base64 encode a byte array.
synchronized void flush()
Flushes this output stream and forces any buffered output bytes to be encoded out to the stream.
synchronized void write(byte[] b, int off, int len)
Encodes len bytes from the specified byte array starting at offset off to this output stream.
void write(byte[] b)
Encodes b.length bytes to this output stream.
synchronized void write(int c)
Encodes the specified byte to this output stream.
[Expand]
Inherited Methods
From class java.io.FilterOutputStream
From class java.io.OutputStream
From class java.lang.Object
From interface java.io.Closeable
From interface java.io.Flushable

Fields

private byte[] buffer

private int bufsize

private int bytesPerLine

private int count

private int lineLimit

private static byte[] newline

private boolean noCRLF

private byte[] outbuf

private static final char[] pem_array

This array maps the characters to their 6 bit values

Public Constructors

public BASE64EncoderStream (OutputStream out, int bytesPerLine)

Create a BASE64 encoder that encodes the specified output stream.

Parameters
out The output stream
bytesPerLine Number of bytes per line. The encoder inserts a CRLF sequence after the specified number of bytes, unless bytesPerLine is Integer.MAX_VALUE, in which case no CRLF is inserted. bytesPerLine is rounded down to a multiple of 4.

public BASE64EncoderStream (OutputStream out)

Create a BASE64 encoder that encodes the specified input stream. Inserts the CRLF sequence after outputting 76 bytes.

Parameters
out The output stream

Public Methods

public synchronized void close ()

Forces any buffered output bytes to be encoded out to the stream and closes this output stream

Throws
IOException

public static byte[] encode (byte[] inbuf)

Base64 encode a byte array. No line breaks are inserted. This method is suitable for short strings, such as those in the IMAP AUTHENTICATE protocol, but not to encode the entire content of a MIME part.

Parameters
inbuf

public synchronized void flush ()

Flushes this output stream and forces any buffered output bytes to be encoded out to the stream.

Throws
IOException if an I/O error occurs.

public synchronized void write (byte[] b, int off, int len)

Encodes len bytes from the specified byte array starting at offset off to this output stream.

Parameters
b The data.
off The start offset in the data.
len The number of bytes to write.
Throws
IOException if an I/O error occurs.

public void write (byte[] b)

Encodes b.length bytes to this output stream.

Parameters
b The data to be written.
Throws
IOException if an I/O error occurs.

public synchronized void write (int c)

Encodes the specified byte to this output stream.

Parameters
c The byte.
Throws
IOException if an I/O error occurs.