Class Base64Ext

java.lang.Object
org.seppiko.commons.utils.codec.Base64Ext
All Implemented Interfaces:
Serializable, BaseNCodec

public class Base64Ext extends Object implements BaseNCodec, Serializable
Base64 EXTension encoding and decoding with custom alphabet.
Author:
Leonard Woo
See Also:
  • 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 Base64Ext instance
      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

      public Base64Ext withoutPadding()
      Returns a Base64 EXTension instance, but without adding any padding character at the end of the encoded byte data.
      Returns:
      this Base64Ext instance
    • setPadding

      public Base64Ext setPadding(char padding) throws IllegalArgumentException
      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 Base64Ext instance.
      Throws:
      IllegalArgumentException - padding character is '\0'.
    • setEncoding

      public Base64Ext setEncoding(Charset encoding)
      Set Base64 EXTension encoding, default is ISO-8859-1.
      Parameters:
      encoding - this Base64Ext encoding.
      Returns:
      this Base64Ext instance.
    • 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

      public String encodeString(byte[] data)
      Base64 EXTension encode the given data and return a newly allocated String with the result.
      Specified by:
      encodeString in interface BaseNCodec
      Parameters:
      data - the data to encode.
      Returns:
      a newly allocated String with the result.
    • decode

      public byte[] decode(byte[] data) throws IllegalArgumentException
      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

      public byte[] decode(String data) throws IllegalArgumentException, NullPointerException
      Decode the Base64 EXTension data in input and return the data in a new byte array.
      Specified by:
      decode in interface BaseNCodec
      Parameters:
      data - the data to decode.
      Returns:
      the data in a new byte array.
      Throws:
      NullPointerException - data is null.
      IllegalArgumentException - data something is wrong.