Package cds.savot.binary
Class Base64
java.lang.Object
cds.savot.binary.Base64
Lets encoding and decoding String with the Base64.
Note: To encode/decode stream of data, you can also use Base64InputStream and Base64OutputStream.
Examples:
public final static void main(final String[] args) throws Exception { String message = "Hi ! If you can read this, the Base64 encoding/decoding has completely worked ! Well done ;-) !"; System.out.println("ORIGINAL MESSAGE:\n\""+message+"\""); String encoded, decoded; System.out.println("\nEncoding...."); encoded = Base64.encodeStr(message); System.out.println("ENCODED MESSAGE:\n\""+encoded+"\""); System.out.println("\nDecoding...."); decoded = Base64.decodeStr(encoded); System.out.println("DECODED MESSAGE:\n\""+decoded+"\""); }
- Since:
- 09/2011
- Author:
- Gregory Mantelet (CDS)
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(char[] encoded) Decodes the given string which is supposed to be encoded in Base64.static byte[]
Decodes the given string which is supposed to be encoded in Base64.static String
Decodes the given string which is supposed to be encoded in Base64.static String
Decodes the given string which is supposed to be encoded in Base64.static String
encode
(byte[] byteArray) Encodes the given bytes array in Base64 characters.static String
Encodes the given string in Base64.static String
Encodes the given string in Base64.
-
Method Details
-
encodeStr
Encodes the given string in Base64.- Parameters:
string
- The string to encode.- Returns:
- Its Base64 encoding.
- See Also:
-
encodeStr
Encodes the given string in Base64. -
encode
Encodes the given bytes array in Base64 characters.- Parameters:
byteArray
- Data to encode.- Returns:
- The encoded data.
-
decodeStr
Decodes the given string which is supposed to be encoded in Base64.- Parameters:
encoded
- Message to decode.- Returns:
- The decoded message.
- Throws:
Base64Exception
- If the encoded message is corrupted (that's to say: not conform to the Base64 encoding).- See Also:
-
decodeStr
Decodes the given string which is supposed to be encoded in Base64.- Parameters:
encoded
- Message to decode.charset
- The name of a supportedcharset
.- Returns:
- The decoded message (string encoded using the given
charset
). - Throws:
Base64Exception
- If the encoded message is corrupted (that's to say: not conform to the Base64 encoding).- See Also:
-
decode
Decodes the given string which is supposed to be encoded in Base64.- Parameters:
encoded
- Data to decode.- Returns:
- The decoded data.
- Throws:
Base64Exception
- If the encoded data are corrupted (that's to say: not conform to the Base64 encoding).- See Also:
-
decode
Decodes the given string which is supposed to be encoded in Base64.- Parameters:
encoded
- Data to decode.- Returns:
- The decoded data.
- Throws:
Base64Exception
- If the encoded data are corrupted (that's to say: not conform to the Base64 encoding).
-