java.lang.Object
org.seppiko.commons.utils.codec.Base64x
- All Implemented Interfaces:
Serializable,BaseNCodec
Base64 eXtension encoding and decoding with custom alphabet.
- Author:
- Leonard Woo
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Base64xBASE64 eXtension with [0-9a-zA-Z@+] padding is '='.static final Base64xBASE64 eXtension with [0-9a-zA-Z@+] padding is '=', and with auto newline 76.static final Base64xBASE64 eXtension with [0-9a-zA-Z@+] and without padding.Fields inherited from interface org.seppiko.commons.utils.codec.BaseNCodec
BIT_WIDTH, BITS_PER_ENCODED_BYTE, BYTES_PER_ENCODED_BLOCK, MASK_2BITS, MASK_4BITS, MASK_5BITS, MASK_6BITS, MASK_8BITS, MASK_UPPER_4BITS -
Constructor Summary
ConstructorsConstructorDescriptionBase64x(char[] base64Table, boolean autoNewline) Base64 eXtension is a custom alphabet implementation based on the Base64 codec algorithm. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]decode(byte[] data) Decode the Base64X-encoded data in input and return the data in a new byte array.byte[]Decode the Base64X-encoded data in input and return the data in a new byte array.byte[]encode(byte[] data) Base64X-encode the given data and return a newly allocated byte array with the result.encodeString(byte[] data) Base64X-encode the given data and return a newly allocated String with the result.setEncoding(Charset encoding) Set Base64X encoding, default isISO-8859-1.setNewline(char[] newline, int linebreakLength) Set newline chars and line break length.setPadding(char padding) Returns a Base64X instance, enable padding and adding a padding character at the end of the encoded byte data.Returns a Base64X instance, but without adding any padding character at the end of the encoded byte data.
-
Field Details
-
BASE64X
BASE64 eXtension with [0-9a-zA-Z@+] padding is '='. -
BASE64X_NEWLINE
BASE64 eXtension with [0-9a-zA-Z@+] padding is '=', and with auto newline 76. -
BASE64X_NON_PADDING
BASE64 eXtension with [0-9a-zA-Z@+] and without padding.
-
-
Constructor Details
-
Base64x
public Base64x(char[] base64Table, boolean autoNewline) Base64 eXtension is a custom alphabet implementation based on the Base64 codec algorithm.- Parameters:
base64Table- base64 alphabet table.autoNewline- enable auto newline. Default is'\r\n'like MIME with at most 76.- Throws:
IllegalArgumentException- base64 alphabet table must have 64 chars.
-
-
Method Details
-
setNewline
public Base64x setNewline(char[] newline, int linebreakLength) throws IllegalArgumentException, NullPointerException Set newline chars and line break length.- Parameters:
newline- newline chars, default is"\r\n".linebreakLength- line break length, default is 76.- Returns:
- this
Base64xinstance - Throws:
IllegalArgumentException- If autoNewline is false throw this.NullPointerException- If newline is null or empty or linebreakLength is less than or equal to 0.
-
withoutPadding
Returns a Base64X instance, but without adding any padding character at the end of the encoded byte data.- Returns:
- this
Base64xinstance
-
setPadding
Returns a Base64X instance, enable padding and adding a padding character at the end of the encoded byte data.- Parameters:
padding- the padding char.- Returns:
- this
Base64xinstance. - Throws:
IllegalArgumentException- padding character is'\0'.
-
setEncoding
Set Base64X encoding, default isISO-8859-1. -
encode
public byte[] encode(byte[] data) Base64X-encode the given data and return a newly allocated byte array with the result.- Parameters:
data- the data to encode.- Returns:
- a newly allocated byte array with the result.
-
encodeString
Base64X-encode the given data and return a newly allocated String with the result.- Specified by:
encodeStringin interfaceBaseNCodec- Parameters:
data- the data to encode.- Returns:
- a newly allocated String with the result.
-
decode
Decode the Base64X-encoded data in input and return the data in a new byte array.- Parameters:
data- Base64 source.- Returns:
- raw byte array.
- Throws:
IllegalArgumentException- data something is wrong.
-
decode
Decode the Base64X-encoded data in input and return the data in a new byte array.- Specified by:
decodein interfaceBaseNCodec- Parameters:
data- the data to decode.- Returns:
- the data in a new byte array.
- Throws:
NullPointerException- data isnull.IllegalArgumentException- data something is wrong.
-