com.bytecream.codec
Class Base64Encoder

java.lang.Object
  extended bycom.bytecream.codec.Base64Encoder

public final class Base64Encoder
extends java.lang.Object

Provides a set of static methods to encode an array of bytes with the Base64 algorithm. The methods encodeToXXXWithLineSeparator(...) use the system line separator provided by System.getProperty("line.separator"). This line separator must be CRLF or a string of length 1.

For the best performance, use this library in server mode and disable assertions.
java -server ...


Method Summary
static byte[] encodeToBytesWithCRLF(byte[] _data, boolean _end)
          Encodes an array of bytes inserting a CRLF every 76 characters.
static byte[] encodeToBytesWithCRLF(byte[] _data, int _offset, int _length, boolean _end)
          Encodes an array of bytes inserting a CRLF every 76 characters.
static byte[] encodeToBytesWithLineSeparator(byte[] _data, boolean _end)
          Encodes an array of bytes inserting the system line separator every 76 characters.
static byte[] encodeToBytesWithoutSeparator(byte[] _data)
          Encodes an array of bytes.
static char[] encodeToCharsWithCRLF(byte[] _data, boolean _end)
          Encodes an array of bytes inserting a CRLF every 76 characters.
static char[] encodeToCharsWithLineSeparator(byte[] _data, boolean _end)
          Encodes an array of bytes inserting the system line separator every 76 characters.
static char[] encodeToCharsWithoutSeparator(byte[] _data)
          Encodes an array of bytes.
static java.lang.String encodeToStringWithCRLF(byte[] _data, boolean _end)
          Encodes an array of bytes inserting a CRLF every 76 characters.
static java.lang.String encodeToStringWithLineSeparator(byte[] _data, boolean _end)
          Encodes an array of bytes inserting the system line separator every 76 characters.
static java.lang.String encodeToStringWithoutSeparator(byte[] _data)
          Encodes an array of bytes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encodeToStringWithCRLF

public static final java.lang.String encodeToStringWithCRLF(byte[] _data,
                                                            boolean _end)
Encodes an array of bytes inserting a CRLF every 76 characters.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
the encoded string.

encodeToCharsWithCRLF

public static final char[] encodeToCharsWithCRLF(byte[] _data,
                                                 boolean _end)
Encodes an array of bytes inserting a CRLF every 76 characters.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
an array of chars containing the encoded data.

encodeToBytesWithCRLF

public static final byte[] encodeToBytesWithCRLF(byte[] _data,
                                                 boolean _end)
Encodes an array of bytes inserting a CRLF every 76 characters.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
an array of bytes containing the encoded data.

encodeToBytesWithCRLF

public static final byte[] encodeToBytesWithCRLF(byte[] _data,
                                                 int _offset,
                                                 int _length,
                                                 boolean _end)
Encodes an array of bytes inserting a CRLF every 76 characters.

Parameters:
_data - the array of bytes to encode.
_offset - the offset within the array of the first byte to be written.
_length - the number of bytes to be read from the given array.
_end - if true add a CRLF at the end.
Returns:
an array of bytes containing the encoded data.

encodeToStringWithLineSeparator

public static final java.lang.String encodeToStringWithLineSeparator(byte[] _data,
                                                                     boolean _end)
Encodes an array of bytes inserting the system line separator every 76 characters. The system line separator must be CRLF or have a length of 1.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
the encoded string
Throws:
java.lang.RuntimeException - if the line separator is not valid.

encodeToCharsWithLineSeparator

public static final char[] encodeToCharsWithLineSeparator(byte[] _data,
                                                          boolean _end)
Encodes an array of bytes inserting the system line separator every 76 characters. The system line separator must be CRLF or have a length of 1.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
an array of chars containing the encoded data.
Throws:
java.lang.RuntimeException - if the line separator is not valid.

encodeToBytesWithLineSeparator

public static final byte[] encodeToBytesWithLineSeparator(byte[] _data,
                                                          boolean _end)
Encodes an array of bytes inserting the system line separator every 76 characters. The system line separator must be CRLF or have a length of 1.

Parameters:
_data - the array of bytes to encode.
_end - if true add a CRLF at the end.
Returns:
an array of bytes containing the encoded data.
Throws:
java.lang.RuntimeException - if the line separator is not valid.

encodeToStringWithoutSeparator

public static final java.lang.String encodeToStringWithoutSeparator(byte[] _data)
Encodes an array of bytes. No separator is inserted. This is usefull for encoding a small amount of bytes, like for data: URLs.

Parameters:
_data - the array of bytes to encode.
Returns:
the encoded string

encodeToCharsWithoutSeparator

public static final char[] encodeToCharsWithoutSeparator(byte[] _data)
Encodes an array of bytes. No separator is inserted. This is usefull for encoding a small amount of bytes, like for data: URLs.

Parameters:
_data - the array of bytes to encode.
Returns:
an array of chars containing the encoded data.

encodeToBytesWithoutSeparator

public static final byte[] encodeToBytesWithoutSeparator(byte[] _data)
Encodes an array of bytes. No separator is inserted. This is usefull for encoding a small amount of bytes, like for data: URLs.

Parameters:
_data - the array of bytes to encode.
Returns:
an array of bytes containing the encoded data.



Copyright © 2004 ByteCream.
All Rights Reserved.