Class Base64Encoding
- Author:
- Laurent Cohen
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidencode(ByteBuffer raw, ByteBuffer encoded) Performs Base64 encoding on therawByteBuffer, writing it to theencodedByteBuffer.static voidencode(ByteBuffer raw, CharBuffer encoded) Performs Base64 encoding on therawByteBuffer, writing it to theencodedCharBuffer.static StringencodeBytes(byte[] source) Encodes a byte array into Base64 notation.static StringencodeBytes(byte[] source, int options) Encodes a byte array into Base64 notation.static StringencodeBytes(byte[] source, int off, int len) Encodes a byte array into Base64 notation.static StringencodeBytes(byte[] source, int off, int len, int options) Encodes a byte array into Base64 notation.static byte[]encodeBytesToBytes(byte[] source) Similar toencodeBytes(byte[])but returnsa byte array instead of instantiating a String.static byte[]encodeBytesToBytes(byte[] source, int off, int len, int options) Similar toencodeBytes(byte[], int, int, int)but returns a byte array instead of instantiating a String.static StringencodeObject(Serializable serializableObject) Serializes an object and returns the Base64-encoded version of that serialized object.static StringencodeObject(Serializable serializableObject, int options) Serializes an object and returns the Base64-encoded version of that serialized object.
-
Constructor Details
-
Base64Encoding
public Base64Encoding()
-
-
Method Details
-
encode
Performs Base64 encoding on therawByteBuffer, writing it to theencodedByteBuffer. This is an experimental feature. Currently it does not pass along any options (such asDO_BREAK_LINESorGZIP.- Parameters:
raw- input bufferencoded- output buffer- Since:
- 2.3
-
encode
Performs Base64 encoding on therawByteBuffer, writing it to theencodedCharBuffer. This is an experimental feature. Currently it does not pass along any options (such asDO_BREAK_LINESorGZIP.- Parameters:
raw- input bufferencoded- output buffer- Since:
- 2.3
-
encodeObject
Serializes an object and returns the Base64-encoded version of that serialized object.As of v 2.3, if the object cannot be serialized or there is another error, the method will throw an IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.
The object is not GZip-compressed before being encoded.- Parameters:
serializableObject- The object to encode- Returns:
- The Base64-encoded object
- Throws:
IOException- if there is an errorNullPointerException- if serializedObject is null- Since:
- 1.4
-
encodeObject
Serializes an object and returns the Base64-encoded version of that serialized object.As of v 2.3, if the object cannot be serialized or there is another error, the method will throw an IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.
The object is not GZip-compressed before being encoded.Example options:
GZIP: gzip-compresses object before encoding it. DO_BREAK_LINES: break lines at 76 characters
Example:
encodeObject( myObj, Base64.GZIP )orExample:
encodeObject( myObj, Base64.GZIP | Base64.DO_BREAK_LINES )- Parameters:
serializableObject- The object to encodeoptions- Specified options- Returns:
- The Base64-encoded object
- Throws:
IOException- if there is an error- Since:
- 2.0
- See Also:
-
encodeBytes
Encodes a byte array into Base64 notation. Does not GZip-compress data.- Parameters:
source- The data to convert- Returns:
- The data in Base64-encoded form
- Throws:
NullPointerException- if source array is null- Since:
- 1.4
-
encodeBytes
Encodes a byte array into Base64 notation.Example options:
GZIP: gzip-compresses object before encoding it. DO_BREAK_LINES: break lines at 76 characters Note: Technically, this makes your encoding non-compliant.Example:
encodeBytes( myData, Base64.GZIP )orExample:
encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES )As of v 2.3, if there is an error with the GZIP stream, the method will throw an IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.
- Parameters:
source- The data to convertoptions- Specified options- Returns:
- The Base64-encoded data as a String
- Throws:
IOException- if there is an errorNullPointerException- if source array is null- Since:
- 2.0
- See Also:
-
encodeBytes
Encodes a byte array into Base64 notation. Does not GZip-compress data.As of v 2.3, if there is an error, the method will throw an IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.
- Parameters:
source- The data to convertoff- Offset in array where conversion should beginlen- Length of data to convert- Returns:
- The Base64-encoded data as a String
- Throws:
NullPointerException- if source array is nullIllegalArgumentException- if source array, offset, or length are invalid- Since:
- 1.4
-
encodeBytes
Encodes a byte array into Base64 notation.Example options:
GZIP: gzip-compresses object before encoding it. DO_BREAK_LINES: break lines at 76 characters Note: Technically, this makes your encoding non-compliant.Example:
encodeBytes( myData, Base64.GZIP )orExample:
encodeBytes( myData, Base64.GZIP | Base64.DO_BREAK_LINES )As of v 2.3, if there is an error with the GZIP stream, the method will throw an IOException. This is new to v2.3! In earlier versions, it just returned a null value, but in retrospect that's a pretty poor way to handle it.
- Parameters:
source- The data to convertoff- Offset in array where conversion should beginlen- Length of data to convertoptions- Specified options- Returns:
- The Base64-encoded data as a String
- Throws:
IOException- if there is an errorNullPointerException- if source array is nullIllegalArgumentException- if source array, offset, or length are invalid- Since:
- 2.0
- See Also:
-
encodeBytesToBytes
public static byte[] encodeBytesToBytes(byte[] source) Similar toencodeBytes(byte[])but returnsa byte array instead of instantiating a String. This is more efficient if you're working with I/O streams and have large data sets to encode.- Parameters:
source- The data to convert- Returns:
- The Base64-encoded data as a byte[] (of ASCII characters)
- Throws:
NullPointerException- if source array is null- Since:
- 2.3.1
-
encodeBytesToBytes
public static byte[] encodeBytesToBytes(byte[] source, int off, int len, int options) throws IOException Similar toencodeBytes(byte[], int, int, int)but returns a byte array instead of instantiating a String. This is more efficient if you're working with I/O streams and have large data sets to encode.- Parameters:
source- The data to convertoff- Offset in array where conversion should beginlen- Length of data to convertoptions- Specified options- Returns:
- The Base64-encoded data as a String
- Throws:
IOException- if there is an errorNullPointerException- if source array is nullIllegalArgumentException- if source array, offset, or length are invalid- Since:
- 2.3.1
- See Also:
-