Class Base64.Builder

All Implemented Interfaces:
Supplier<Base64>
Enclosing class:
Base64

public static class Base64.Builder extends BaseNCodec.AbstractBuilder<Base64,Base64.Builder>
Builds Base64 instances.

To configure a new instance, use a Base64.Builder. For example:

 Base64 base64 = Base64.builder()
   .setCodecPolicy(CodecPolicy.LENIENT)       // default is lenient, null resets to default
   .setEncodeTable(customEncodeTable)         // default is built in, null resets to default
   .setLineLength(0)                          // default is none
   .setLineSeparator('\r', '\n')              // default is CR LF, null resets to default
   .setPadding('=')                           // default is '='
   .setUrlSafe(false)                         // default is false
   .get()
 
Since:
1.17.0
  • Constructor Details

    • Builder

      public Builder()
      Constructs a new instance.
  • Method Details

    • get

      public Base64 get()
    • setDecodeTableFormat

      public Base64.Builder setDecodeTableFormat(Base64.DecodeTableFormat format)
      Sets the format of the decoding table. This method allows callers to explicitly state whether a standard or URL-safe Base64 decoding is expected. This method does not modify behavior on encoding operations. For configuration of the encoding behavior, please use setUrlSafe(boolean) method.

      By default, the implementation uses the Base64.DecodeTableFormat.MIXED approach, allowing a seamless handling of both Base64.DecodeTableFormat.URL_SAFE and Base64.DecodeTableFormat.STANDARD base64 in lenient mode. Strict decoding additionally requires each character to match the configured encoding table.

      Parameters:
      format - table format to be used on Base64 decoding. Use Base64.DecodeTableFormat.MIXED or null to reset to the default behavior.
      Returns:
      this instance.
      Since:
      1.21
    • setEncodeTable

      public Base64.Builder setEncodeTable(byte... encodeTable)
      Sets the encode table.
      Overrides:
      setEncodeTable in class BaseNCodec.AbstractBuilder<Base64,Base64.Builder>
      Parameters:
      encodeTable - The encode table with exactly 64 unique entries, null resets to the default.
      Returns:
      this instance.
      Throws:
      IllegalArgumentException - Thrown if encodeTable does not contain exactly 64 unique entries.
    • setUrlSafe

      public Base64.Builder setUrlSafe(boolean urlSafe)
      Sets the URL-safe encoding policy.

      Strict decoding requires this alphabet and its padding convention. Lenient decoding accepts both alphabets by default; use Builder.setDecodeTableFormat(DecodeTableFormat) to select a decoding table.

      Parameters:
      urlSafe - URL-safe encoding policy.
      Returns:
      this instance.