Package cl.obcom.desktopfx.util
Class Base64
java.lang.Object
cl.obcom.desktopfx.util.Base64
Base64 encoders and decoders. This class supports the following types of Base64 as specified in RFC 4648:
- Basic:
Uses "The Base64 Alphabet" as specified in Table 1 of RFC 4648 for encoding and decoding operation. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
- URL and Filename Safe:
Uses the "URL and Filename Safe Base64 Alphabet" as specified in Table 2 of RFC 4648 for encoding and decoding. The encoder does not add any line feed (line separator) character. The decoder rejects data that contains characters outside the base64 alphabet.
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
decode
(char[] chars, int offset, int length, boolean urlSafe) Decodes a byte array from supplied Base64 character sequence.static byte[]
decodeBasic
(char[] chars) Decodes a byte array from supplied Base64 Basic character array.static byte[]
decodeBasic
(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 Basic character sequence.static byte[]
decodeBasic
(String str) Decodes a byte array from supplied Base64 Basic string.static byte[]
decodeUrlSafe
(char[] chars) Decodes a byte array from supplied Base64 URL Safe character array.static byte[]
decodeUrlSafe
(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 URL Safe character sequence.static byte[]
decodeUrlSafe
(String str) Decodes a byte array from supplied Base64 URL Safe string.static String
encode
(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied bytes into a string using Base64 encoding scheme.static String
encodeBasic
(byte[] bytes) Encodes supplied byte array to a Base64 Basic representation.static String
encodeBasic
(byte[] bytes, int offset, int length) Encodes supplied byte sequence to a Base64 Basic representation.static byte[]
encodeToBytes
(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied bytes into a byte array using Base64 encoding scheme.static String
encodeUrlSafe
(byte[] bytes) Encodes supplied byte array to a Base64 URL Safe representation.static String
encodeUrlSafe
(byte[] bytes, int offset, int length) Encodes supplied byte sequence to a Base64 URL Safe representation.
-
Method Details
-
encodeBasic
Encodes supplied byte array to a Base64 Basic representation.- Parameters:
bytes
- the byte array to encode.- Returns:
- the Base64 Basic representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
encodeBasic
Encodes supplied byte sequence to a Base64 Basic representation.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.- Returns:
- the Base64 Basic representation of specified bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
encodeUrlSafe
Encodes supplied byte array to a Base64 URL Safe representation.- Parameters:
bytes
- the byte array to encode.- Returns:
- the Base64 URL Safe representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.
-
encodeUrlSafe
Encodes supplied byte sequence to a Base64 URL Safe representation.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.- Returns:
- the Base64 URL Safe representation of specified bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
encode
public static String encode(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied bytes into a string using Base64 encoding scheme.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.urlSafe
- iftrue
use Base64 URL Safe encoding.addPadding
- iftrue
add "=" padding characters.- Returns:
- a string with the Base64 representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
encodeToBytes
public static byte[] encodeToBytes(byte[] bytes, int offset, int length, boolean urlSafe, boolean addPadding) Encodes supplied bytes into a byte array using Base64 encoding scheme.- Parameters:
bytes
- the byte array to encode.offset
- the index of first byte to encode.length
- the number of bytes to encode.urlSafe
- iftrue
use Base64 URL Safe encoding.addPadding
- iftrue
add "=" padding characters.- Returns:
- a byte array with the Base64 representation of supplied bytes.
- Throws:
NullPointerException
- ifbytes
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decodeBasic
Decodes a byte array from supplied Base64 Basic string.- Parameters:
str
- the string to decode.- Returns:
- the byte array decoded from supplied string.
- Throws:
NullPointerException
- ifstr
isnull
.IllegalArgumentException
- ifstr
is invalid.
-
decodeBasic
public static byte[] decodeBasic(char[] chars) Decodes a byte array from supplied Base64 Basic character array.- Parameters:
chars
- the character array to decode.- Returns:
- the byte array decoded from supplied characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- ifchars
is invalid.
-
decodeBasic
public static byte[] decodeBasic(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 Basic character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.- Returns:
- the byte array decoded from specified characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decodeUrlSafe
Decodes a byte array from supplied Base64 URL Safe string.- Parameters:
str
- the string to decode.- Returns:
- the byte array decoded from supplied string.
- Throws:
NullPointerException
- ifstr
isnull
.IllegalArgumentException
- ifstr
is invalid.
-
decodeUrlSafe
public static byte[] decodeUrlSafe(char[] chars) Decodes a byte array from supplied Base64 URL Safe character array.- Parameters:
chars
- the character array to decode.- Returns:
- the byte array decoded from supplied characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- ifchars
is invalid.
-
decodeUrlSafe
public static byte[] decodeUrlSafe(char[] chars, int offset, int length) Decodes a byte array from supplied Base64 URL Safe character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.- Returns:
- the byte array decoded from specified characters.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-
decode
public static byte[] decode(char[] chars, int offset, int length, boolean urlSafe) Decodes a byte array from supplied Base64 character sequence.- Parameters:
chars
- the character array to decode.offset
- the index of first character to decode.length
- the number of characters to decode.urlSafe
- iftrue
use Base64 URL Safe decoding.- Returns:
- the byte array decoded from specified character sequence.
- Throws:
NullPointerException
- ifchars
isnull
.IllegalArgumentException
- if an argument is invalid.IndexOutOfBoundsException
- if an argument is out-of-bounds.
-