Top Description Fields Constructors Methods
com.sun.mail.util

public Class BASE64EncoderStream

extends FilterOutputStream
Class Inheritance
Known Direct Subclasses
com.sun.mail.util.BEncoderStream
Imports
java.io.*

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.
Authors
John Mani, Bill Shannon

Field Summary

Modifier and TypeField and Description
private byte[]
private int
private int
private int
private int
private static byte[]
private boolean
private byte[]
private static final char[]
pem_array

This array maps the characters to their 6 bit values

Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
public
BASE64EncoderStream(OutputStream
the output stream
out
,
int
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.
bytesPerLine
)

Create a BASE64 encoder that encodes the specified output stream.

public
BASE64EncoderStream(OutputStream
the output stream
out
)

Create a BASE64 encoder that encodes the specified input stream.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Forces any buffered output bytes to be encoded out to the stream and closes this output stream
private void
encode()

Encode the data stored in buffer.

public static byte[]

Returns:

the encoded byte array
encode
(byte[]
the byte array
inbuf
)

Base64 encode a byte array.

private static byte[]
encode(byte[] inbuf, int off, int size, byte[] outbuf)

Internal use only version of encode.

private static int
encodedSize(int size)

Return the corresponding encoded size for the given number of bytes, not including any CRLF.

public synchronized void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes this output stream and forces any buffered output bytes to be encoded out to the stream.
public synchronized void
write(byte[]
the data.
b
,
int
the start offset in the data.
off
,
int
the number of bytes to write.
len
)

Overrides java.io.FilterOutputStream.write.

Encodes len bytes from the specified byte array starting at offset off to this output stream.
public void
write(byte[]
the data to be written.
b
)

Overrides java.io.FilterOutputStream.write.

Encodes b.length bytes to this output stream.
public synchronized void
write(int
the byte.
c
)

Overrides java.io.FilterOutputStream.write.

Encodes the specified byte to this output stream.

Field Detail

bufferback to summary
private byte[] buffer
bufsizeback to summary
private int bufsize
bytesPerLineback to summary
private int bytesPerLine
countback to summary
private int count
lineLimitback to summary
private int lineLimit
newlineback to summary
private static byte[] newline
noCRLFback to summary
private boolean noCRLF
outbufback to summary
private byte[] outbuf
pem_arrayback to summary
private static final char[] pem_array

This array maps the characters to their 6 bit values

Constructor Detail

BASE64EncoderStreamback to summary
public BASE64EncoderStream(OutputStream out, int bytesPerLine)

Create a BASE64 encoder that encodes the specified output stream.

Parameters
out:OutputStream

the output stream

bytesPerLine:int

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.

BASE64EncoderStreamback to summary
public BASE64EncoderStream(OutputStream out)

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

Parameters
out:OutputStream

the output stream

Method Detail

closeback to summary
public synchronized void close() throws IOException

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

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

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterOutputStream.close.

if an I/O error occurs.

encodeback to summary
private void encode() throws IOException

Encode the data stored in buffer. Uses outbuf to store the encoded data before writing.

Exceptions
IOException:
if an I/O error occurs.
encodeback to summary
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:byte[]

the byte array

Returns:byte[]

the encoded byte array

encodeback to summary
private static byte[] encode(byte[] inbuf, int off, int size, byte[] outbuf)

Internal use only version of encode. Allow specifying which part of the input buffer to encode. If outbuf is non-null, it's used as is. Otherwise, a new output buffer is allocated.

encodedSizeback to summary
private static int encodedSize(int size)

Return the corresponding encoded size for the given number of bytes, not including any CRLF.

flushback to summary
public synchronized void flush() throws IOException

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public synchronized void write(byte[] b, int off, int len) throws IOException

Overrides java.io.FilterOutputStream.write.

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

Parameters
b:byte[]

the data.

off:int

the start offset in the data.

len:int

the number of bytes to write.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public void write(byte[] b) throws IOException

Overrides java.io.FilterOutputStream.write.

Encodes b.length bytes to this output stream.

Parameters
b:byte[]

the data to be written.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
writeback to summary
public synchronized void write(int c) throws IOException

Overrides java.io.FilterOutputStream.write.

Encodes the specified byte to this output stream.

Parameters
c:int

the byte.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.