org.apache.geronimo.mail.util
Class Base64Encoder

java.lang.Object
  extended by org.apache.geronimo.mail.util.Base64Encoder
All Implemented Interfaces:
Encoder

public class Base64Encoder
extends Object
implements Encoder


Field Summary
protected  byte[] decodingTable
           
protected  byte[] encodingTable
           
protected  byte padding
           
 
Constructor Summary
Base64Encoder()
           
 
Method Summary
 int decode(byte[] data, int off, int length, byte[] out)
          decode the base 64 encoded byte data writing it to the provided byte array buffer.
 int decode(byte[] data, int off, int length, OutputStream out)
          decode the base 64 encoded byte data writing it to the given output stream, whitespace characters will be ignored.
 int decode(String data, OutputStream out)
          decode the base 64 encoded String data writing it to the given output stream, whitespace characters will be ignored.
 int encode(byte[] data, int off, int length, OutputStream out)
          encode the input data producing a base 64 output stream.
 void encode(InputStream in, StringBuffer out, int limit)
          encode the input data producing a base 64 output stream.
 void encodeWord(byte[] data, StringBuffer out, String charset)
          Perform RFC-2047 word encoding using Base64 data encoding.
 void encodeWord(InputStream in, String charset, OutputStream out, boolean fold)
          Perform RFC-2047 word encoding using Base64 data encoding.
 void encodeWordData(byte[] data, StringBuffer out)
          encode the input data producing a base 64 output stream.
 int estimateEncodedLength(byte[] data)
          Estimate the final encoded size of a segment of data.
protected  void initialiseDecodingTable()
           
 boolean isValidBase64(int ch)
          Test if a character is a valid Base64 encoding character.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encodingTable

protected final byte[] encodingTable

padding

protected byte padding

decodingTable

protected final byte[] decodingTable
Constructor Detail

Base64Encoder

public Base64Encoder()
Method Detail

initialiseDecodingTable

protected void initialiseDecodingTable()

encode

public int encode(byte[] data,
                  int off,
                  int length,
                  OutputStream out)
           throws IOException
encode the input data producing a base 64 output stream.

Specified by:
encode in interface Encoder
Returns:
the number of bytes produced.
Throws:
IOException

decode

public int decode(byte[] data,
                  int off,
                  int length,
                  OutputStream out)
           throws IOException
decode the base 64 encoded byte data writing it to the given output stream, whitespace characters will be ignored.

Specified by:
decode in interface Encoder
Returns:
the number of bytes produced.
Throws:
IOException

decode

public int decode(String data,
                  OutputStream out)
           throws IOException
decode the base 64 encoded String data writing it to the given output stream, whitespace characters will be ignored.

Specified by:
decode in interface Encoder
Returns:
the number of bytes produced.
Throws:
IOException

decode

public int decode(byte[] data,
                  int off,
                  int length,
                  byte[] out)
           throws IOException
decode the base 64 encoded byte data writing it to the provided byte array buffer.

Returns:
the number of bytes produced.
Throws:
IOException

isValidBase64

public boolean isValidBase64(int ch)
Test if a character is a valid Base64 encoding character. This must be either a valid digit or the padding character ("=").

Parameters:
ch - The test character.
Returns:
true if this is valid in Base64 encoded data, false otherwise.

encodeWord

public void encodeWord(InputStream in,
                       String charset,
                       OutputStream out,
                       boolean fold)
                throws IOException
Perform RFC-2047 word encoding using Base64 data encoding.

Parameters:
in - The source for the encoded data.
charset - The charset tag to be added to each encoded data section.
out - The output stream where the encoded data is to be written.
fold - Controls whether separate sections of encoded data are separated by linebreaks or whitespace.
Throws:
IOException

encodeWord

public void encodeWord(byte[] data,
                       StringBuffer out,
                       String charset)
                throws IOException
Perform RFC-2047 word encoding using Base64 data encoding.

Parameters:
in - The source for the encoded data.
charset - The charset tag to be added to each encoded data section.
out - The output stream where the encoded data is to be written.
fold - Controls whether separate sections of encoded data are separated by linebreaks or whitespace.
Throws:
IOException

encodeWordData

public void encodeWordData(byte[] data,
                           StringBuffer out)
encode the input data producing a base 64 output stream.


encode

public void encode(InputStream in,
                   StringBuffer out,
                   int limit)
            throws IOException
encode the input data producing a base 64 output stream.

Throws:
IOException

estimateEncodedLength

public int estimateEncodedLength(byte[] data)
Estimate the final encoded size of a segment of data. This is used to ensure that the encoded blocks do not get split across a unicode character boundary and that the encoding will fit within the bounds of a mail header line.

Parameters:
data - The data we're anticipating encoding.
Returns:
The size of the byte data in encoded form.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.