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

public Class BASE64DecoderStream

extends FilterInputStream
Class Inheritance
Imports
java.io.*

This class implements a BASE64 Decoder. It is implemented as a FilterInputStream, so one can just wrap this class around any input stream and read bytes from this filter. The decoding is done as the bytes are read out.
Authors
John Mani, Bill Shannon

Field Summary

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

This character array provides the character to value map based on RFC1521.

private static final byte[]
Inherited from java.io.FilterInputStream:
in

Constructor Summary

AccessConstructor and Description
public
BASE64DecoderStream(InputStream
the input stream
in
)

Create a BASE64 decoder that decodes the specified input stream.

public
BASE64DecoderStream(InputStream
the input stream
in
,
boolean
ignore errors in encoded data?
ignoreErrors
)

Create a BASE64 decoder that decodes the specified input stream.

Method Summary

Modifier and TypeMethod and Description
public int
available()

Overrides java.io.FilterInputStream.available.

Returns the number of bytes that can be read from this input stream without blocking.
private int

Returns:

the number of bytes filled, always a multiple of three, and may be zero
decode
(byte[]
the buffer into which to put the decoded bytes
outbuf
,
int
position in the buffer to start filling
pos
,
int
the number of bytes to fill
len
)

The decoder algorithm.

public static byte[]

Returns:

the decoded byte array
decode
(byte[]
the byte array
inbuf
)

Base64 decode a byte array.

private int

Returns:

the next byte, -1 on EOF, or -2 if next byte is '=' (padding at end of encoded data)
getByte
()

Read the next valid byte from the input stream.

public boolean
markSupported()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports marks.
public int

Returns:

next byte of data, or -1 if the end of the stream is reached.
read
()

Overrides java.io.FilterInputStream.read.

Read the next decoded byte from this input stream.
public int

Returns:

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.
read
(byte[]
the buffer into which the data is read.
buf
,
int
the start offset of the data.
off
,
int
the maximum number of bytes read.
len
)

Overrides java.io.FilterInputStream.read.

Reads up to len decoded bytes of data from this input stream into an array of bytes.
private String
recentChars()

Return the most recent characters, for use in an error message.

public long
skip(long
the number of bytes to be skipped.
n
)

Overrides java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from this stream.
Inherited from java.io.FilterInputStream:
closemarkreadreset

Field Detail

bufferback to summary
private byte[] buffer
bufsizeback to summary
private int bufsize
ignoreErrorsback to summary
private boolean ignoreErrors
indexback to summary
private int index
input_bufferback to summary
private byte[] input_buffer
input_lenback to summary
private int input_len
input_posback to summary
private int input_pos
pem_arrayback to summary
private static final char[] pem_array

This character array provides the character to value map based on RFC1521.

pem_convert_arrayback to summary
private static final byte[] pem_convert_array

Constructor Detail

BASE64DecoderStreamback to summary
public BASE64DecoderStream(InputStream in)

Create a BASE64 decoder that decodes the specified input stream. The System property mail.mime.base64.ignoreerrors controls whether errors in the encoded data cause an exception or are ignored. The default is false (errors cause exception).

Parameters
in:InputStream

the input stream

BASE64DecoderStreamback to summary
public BASE64DecoderStream(InputStream in, boolean ignoreErrors)

Create a BASE64 decoder that decodes the specified input stream.

Parameters
in:InputStream

the input stream

ignoreErrors:boolean

ignore errors in encoded data?

Method Detail

availableback to summary
public int available() throws IOException

Overrides java.io.FilterInputStream.available.

Returns the number of bytes that can be read from this input stream without blocking. However, this figure is only a close approximation in case the original encoded stream contains embedded CRLFs; since the CRLFs are discarded, not decoded

Returns:int

Doc from java.io.FilterInputStream.available.

an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.available.

if an I/O error occurs.

decodeback to summary
private int decode(byte[] outbuf, int pos, int len) throws IOException

The decoder algorithm. Most of the complexity here is dealing with error cases. Returns the number of bytes decoded, which may be zero. Decoding is done by filling an int with 4 6-bit values by shifting them in from the bottom and then extracting 3 8-bit bytes from the int by shifting them out from the bottom.

Parameters
outbuf:byte[]

the buffer into which to put the decoded bytes

pos:int

position in the buffer to start filling

len:int

the number of bytes to fill

Returns:int

the number of bytes filled, always a multiple of three, and may be zero

Exceptions
IOException:
if the data is incorrectly formatted
decodeback to summary
public static byte[] decode(byte[] inbuf)

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

Note

inbuf may only contain valid base64 characters. Whitespace is not ignored.

Parameters
inbuf:byte[]

the byte array

Returns:byte[]

the decoded byte array

getByteback to summary
private int getByte() throws IOException

Read the next valid byte from the input stream. Buffer lots of data from underlying stream in input_buffer, for efficiency.

Returns:int

the next byte, -1 on EOF, or -2 if next byte is '=' (padding at end of encoded data)

markSupportedback to summary
public boolean markSupported()

Overrides java.io.FilterInputStream.markSupported.

Tests if this input stream supports marks. Currently this class does not support marks

Returns:boolean

Doc from java.io.FilterInputStream.markSupported.

true if this stream type supports the mark and reset method; false otherwise.

Annotations
@Override
readback to summary
public int read() throws IOException

Overrides java.io.FilterInputStream.read.

Read the next decoded byte from this input stream. The byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.

Returns:int

next byte of data, or -1 if the end of the stream is reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
See Also
java.io.FilterInputStream#in
readback to summary
public int read(byte[] buf, int off, int len) throws IOException

Overrides java.io.FilterInputStream.read.

Reads up to len decoded bytes of data from this input stream into an array of bytes. This method blocks until some input is available.

Parameters
buf:byte[]

the buffer into which the data is read.

off:int

the start offset of the data.

len:int

the maximum number of bytes read.

Returns:int

the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs.
recentCharsback to summary
private String recentChars()

Return the most recent characters, for use in an error message.

skipback to summary
public long skip(long n) throws IOException

Overrides java.io.FilterInputStream.skip.

Skips over and discards n bytes of data from this stream.

Parameters
n:long

Doc from java.io.FilterInputStream.skip.

the number of bytes to be skipped.

Returns:long

Doc from java.io.FilterInputStream.skip.

the actual number of bytes skipped.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.FilterInputStream.skip.

if in.skip(n) throws an IOException.