Package africa.absa.inception.core.util
Class Base64Util
- java.lang.Object
-
- africa.absa.inception.core.util.Base64Util
-
public class Base64Util extends Object
The Base64Util class provides a number of Base-64 related utility functions.- Author:
- Robert Harder, Marcus Portmann
-
-
Field Summary
Fields Modifier and Type Field Description static byteBAD_ENCODINGIndicates error in encoding.static booleanCOMPRESSSpecify that data should be compressed (value is true).static booleanDECODESpecify decoding (value is false).static booleanDONT_COMPRESSSpecify that data should not be compressed (value is false).static booleanENCODESpecify encoding (value is true).static byteEQUALS_SIGN_ENCIndicates equals sign in encoding.static byteWHITE_SPACE_ENCIndicates white space in encoding.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]decode(byte[] source, int off, int len)Decodes Base64Util content in byte array format and returns the decoded byte array.static byte[]decode(String s)Decodes data from Base64Util notation.static Optional<Object>decodeToObject(String encodedObject)Attempts to decode Base64Util data and deserialize a Java Object within.static StringdecodeToString(String s)Decodes data from Base64Util notation and returns it as a string.static StringencodeBytes(byte[] source)Encodes a byte array into Base64Util notation.static StringencodeBytes(byte[] source, boolean breakLines)Encodes a byte array into Base64Util notation.static StringencodeBytes(byte[] source, int off, int len)Encodes a byte array into Base64Util notation.static StringencodeBytes(byte[] source, int off, int len, boolean breakLines)Encodes a byte array into Base64Util notation.static StringencodeString(String s)Encodes a string in Base64Util notation with line breaks after every 75 Base64Util characters.static StringencodeString(String s, boolean breakLines)Encodes a string in Base64Util notation with line breaks after every 75 Base64Util characters.
-
-
-
Field Detail
-
BAD_ENCODING
public static final byte BAD_ENCODING
Indicates error in encoding.
-
COMPRESS
public static final boolean COMPRESS
Specify that data should be compressed (value is true).- See Also:
- Constant Field Values
-
DECODE
public static final boolean DECODE
Specify decoding (value is false).- See Also:
- Constant Field Values
-
DONT_COMPRESS
public static final boolean DONT_COMPRESS
Specify that data should not be compressed (value is false).- See Also:
- Constant Field Values
-
ENCODE
public static final boolean ENCODE
Specify encoding (value is true).- See Also:
- Constant Field Values
-
EQUALS_SIGN_ENC
public static final byte EQUALS_SIGN_ENC
Indicates equals sign in encoding.
-
WHITE_SPACE_ENC
public static final byte WHITE_SPACE_ENC
Indicates white space in encoding.
-
-
Method Detail
-
decode
public static byte[] decode(String s)
Decodes data from Base64Util notation.- Parameters:
s- the string to decode- Returns:
- the decoded data
- Since:
- 1.4
-
decode
public static byte[] decode(byte[] source, int off, int len)Decodes Base64Util content in byte array format and returns the decoded byte array.- Parameters:
source- the Base64Util encoded dataoff- the offset of where to begin decodinglen- the length of characters to decode- Returns:
- decoded data
- Since:
- 1.3
-
decodeToObject
public static Optional<Object> decodeToObject(String encodedObject)
Attempts to decode Base64Util data and deserialize a Java Object within. Returns null if there was an error.- Parameters:
encodedObject- the Base64Util data to decode- Returns:
- an Optional containing the decoded and deserialized object or an empty Optional if there was an error
- Since:
- 1.4
-
decodeToString
public static String decodeToString(String s)
Decodes data from Base64Util notation and returns it as a string. Equivlaent to calling new String(decode(s))- Parameters:
s- the string to decode- Returns:
- the data as a string
- Since:
- 1.4
-
encodeBytes
public static String encodeBytes(byte[] source)
Encodes a byte array into Base64Util notation. Equivalent to calling encodeBytes(source, 0, source.length)- Parameters:
source- the data to convert- Returns:
- the Base64Util encoded string
- Since:
- 1.4
-
encodeBytes
public static String encodeBytes(byte[] source, boolean breakLines)
Encodes a byte array into Base64Util notation. Equivalent to calling encodeBytes(source, 0, source.length)- Parameters:
source- the data to convertbreakLines- break lines at 80 characters or less- Returns:
- the Base64Util encoded bytes
- Since:
- 1.4
-
encodeBytes
public static String encodeBytes(byte[] source, int off, int len)
Encodes a byte array into Base64Util notation.- Parameters:
source- the data to convertoff- offset in array where conversion should beginlen- length of data to convert- Returns:
- the Base64Util encoded bytes
- Since:
- 1.4
-
encodeBytes
public static String encodeBytes(byte[] source, int off, int len, boolean breakLines)
Encodes a byte array into Base64Util notation.- Parameters:
source- the data to convertoff- offset in array where conversion should beginlen- length of data to convertbreakLines- break lines at 80 characters or less- Returns:
- the Base64Util encoded bytes
- Since:
- 1.4
-
encodeString
public static String encodeString(String s)
Encodes a string in Base64Util notation with line breaks after every 75 Base64Util characters. Of course you probably only need to encode a string if there are non-ASCII characters in it such as many non-English languages.- Parameters:
s- the string to encode- Returns:
- the encoded string
- Since:
- 1.3
-
encodeString
public static String encodeString(String s, boolean breakLines)
Encodes a string in Base64Util notation with line breaks after every 75 Base64Util characters. Of course you probably only need to encode a string if there are non-ASCII characters in it such as many non-English languages.- Parameters:
s- the string to encodebreakLines- break lines at 80 characters or less- Returns:
- the encoded string
- Since:
- 1.3
-
-