java.lang.Object
org.seppiko.commons.utils.codec.Base64Ext
- All Implemented Interfaces:
Serializable,BaseNCodec
Base64 EXTension encoding and decoding with custom alphabet.
- Author:
- Leonard Woo
- See Also:
-
Field Summary
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
ConstructorsConstructorDescriptionBase64Ext(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 Base64 EXTension data in input and return the data in a new byte array.byte[]Decode the Base64 EXTension data in input and return the data in a new byte array.byte[]encode(byte[] data) Base64 EXTension encode the given data and return a newly allocated byte array with the result.encodeString(byte[] data) Base64 EXTension encode the given data and return a newly allocated String with the result.setEncoding(Charset encoding) Set Base64 EXTension encoding, default isISO-8859-1.setNewline(char[] newline, int linebreakLength) Set newline chars and line break length.setPadding(char padding) Returns a Base64 EXTension instance, enable padding and adding a padding character at the end of the encoded byte data.Returns a Base64 EXTension instance, but without adding any padding character at the end of the encoded byte data.
-
Constructor Details
-
Base64Ext
public Base64Ext(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 Base64Ext 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
Base64Extinstance - 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 Base64 EXTension instance, but without adding any padding character at the end of the encoded byte data.- Returns:
- this
Base64Extinstance
-
setPadding
Returns a Base64 EXTension instance, enable padding and adding a padding character at the end of the encoded byte data.- Parameters:
padding- the padding char.- Returns:
- this
Base64Extinstance. - Throws:
IllegalArgumentException- padding character is'\0'.
-
setEncoding
Set Base64 EXTension encoding, default isISO-8859-1. -
encode
public byte[] encode(byte[] data) Base64 EXTension 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
Base64 EXTension 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 Base64 EXTension 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 Base64 EXTension 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.
-