Class Base64Converter
- java.lang.Object
-
- com.redwood.scheduler.infrastructure.text.api.Base64Converter
-
public class Base64Converter extends Object
-
-
Constructor Summary
Constructors Constructor Description Base64Converter()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
decode(byte[] base64Data)
Decodes Base64 data into a byte array.static byte[]
decode(byte[] base64Data, int dataLength)
Decodes Base64 data into a byte array.static String
decode(String s)
Decode the Base64 data into a String.static String
decode(String s, String charsetName)
Decode the Base64 data into a String.static byte[]
encode(byte[] rawData)
Encode a byte array to the corresponding Base64 byte array.static byte[]
encode(byte[] rawData, int dataLength)
Convert the firstdataLength
bytes ofrawData
to the corresponding Base64 byte array.static String
encode(String s)
Encode a string using the Base64 encoding.static String
encode(String s, String charsetName)
Encode a string using the Base64 encoding.static String
encode(String s, Charset charset)
Encode a string using the Base64 encoding.static String
encode2String(byte[] rawData)
Encode a byte array to the corresponding Base64 String.
-
-
-
Method Detail
-
encode
public static String encode(String s)
Encode a string using the Base64 encoding. This is equivalent to callingencode(String, String)
and specifying the "UTF-8" character set. The following table gives some sample encodings:Example calls with their corresponding results call result encode("A") "QQ==" encode("AA") "QUE=" encode("AAA") "QUFB" encode("Å") "w4U=" encode("ÅÅ") "w4XDhQ==" encode("ÅÅÅ") "w4XDhcOF" - Parameters:
s
- the string to be Base64 encoded- Returns:
- the Base64 encoded string
-
encode
public static String encode(String s, String charsetName) throws UnsupportedEncodingException
Encode a string using the Base64 encoding. The string is converted to bytes using the specified encoding. The following table gives some sample encodings:Example calls with their corresponding results call result Base64Converter.encode("AAA", "UTF-8") "QUFB" Base64Converter.encode("Å", "UTF-8") "w4U=" Base64Converter.encode("ÅÅÅ", "UTF-8") "w4XDhcOF" Base64Converter.encode("AAA", "ISO8859-15") "QUFB" Base64Converter.encode("Å", "ISO8859-15") "xQ==" Base64Converter.encode("ÅÅÅ", "ISO8859-15") "xcXF" - Parameters:
s
- the string to be Base64 encodedcharsetName
- the encoding to use to convert the string into bytes to encode- Returns:
- the Base64 encoded string
- Throws:
UnsupportedEncodingException
- if the encoding is not known to the Java runtime.- See Also:
encode(String, Charset)
-
encode
public static String encode(String s, Charset charset)
Encode a string using the Base64 encoding. The string is converted to bytes using the specified encoding. The following table gives some sample encodings:Example calls with their corresponding results call result Base64Converter.encode("AAA", "UTF-8") "QUFB" Base64Converter.encode("Å", "UTF-8") "w4U=" Base64Converter.encode("ÅÅÅ", "UTF-8") "w4XDhcOF" Base64Converter.encode("AAA", "ISO8859-15") "QUFB" Base64Converter.encode("Å", "ISO8859-15") "xQ==" Base64Converter.encode("ÅÅÅ", "ISO8859-15") "xcXF" - Parameters:
s
- the string to be Base64 encodedcharset
- the encoding to use to convert the string into bytes to encode- Returns:
- the Base64 encoded string
-
encode
public static byte[] encode(byte[] rawData)
Encode a byte array to the corresponding Base64 byte array.- Parameters:
rawData
- the data to encoded- Returns:
- the Base64 encoded bytes. These bytes are equivalent to the the ASCII encoded Base64 string.
-
encode2String
public static String encode2String(byte[] rawData)
Encode a byte array to the corresponding Base64 String. This is equivalent to callingnew String(encode(rawData), "UTF-8")
.- Parameters:
rawData
- the data to encoded- Returns:
- The Base64 encoded String.
-
encode
public static byte[] encode(byte[] rawData, int dataLength)
Convert the firstdataLength
bytes ofrawData
to the corresponding Base64 byte array.- Parameters:
rawData
- the data to encodeddataLength
- the number of bytes to encode- Returns:
- the Base64 encoded bytes. These bytes are equivalent to the the ASCII encoded Base64 string.
-
decode
public static String decode(String s)
Decode the Base64 data into a String. The returned String is the one created by converting the bytes into a String using the UTF-8 data encoding. The following table gives some sample decodings:Example calls with their corresponding results call result Base64Converter.decode("w6vDq8Or") "ëëë" Base64Converter.encode("QUFB")) "AAA" Base64Converter.encode("w4U=") "Å" Base64Converter.encode("w4XDhcOF") "ÅÅÅ" - Parameters:
s
- the string to decode- Returns:
- the results of decoding the string.
-
decode
public static String decode(String s, String charsetName) throws UnsupportedEncodingException
Decode the Base64 data into a String. The returned String is the one created by converting the bytes into a String using the given encoding. The following table gives some sample decodings:Example calls with their corresponding results call result Base64Converter.decode("w6vDq8Or", "UTF-8") "ëëë" Base64Converter.decode("w6vDq8Or", "ISO8859-15") "ëëë" - Parameters:
s
- the string to decodecharsetName
- the encoding to use to convert the string into bytes to encode- Returns:
- the results of decoding the string.
- Throws:
UnsupportedEncodingException
- if the encoding is not known to the Java runtime.
-
decode
public static byte[] decode(byte[] base64Data)
Decodes Base64 data into a byte array.- Parameters:
base64Data
- byte array containing Base64 data. This array is assumed to be a multiple of four in length.- Returns:
- array containing decoded data.
-
decode
public static byte[] decode(byte[] base64Data, int dataLength)
Decodes Base64 data into a byte array.- Parameters:
base64Data
- byte array containing Base64 data. This array is assumed to be a multiple of four in length.dataLength
- the number of bytes to decode- Returns:
- array containing decoded data.
-
-