org.apache.hc.client5.http.utils

## Class Base64

- java.lang.Object
- - org.apache.hc.client5.http.utils.Base64

-     @Internal
      public class Base64
      extends Object

  Provide implementations of the Base64 conversion methods from Commons Codec, delegating to the Java Base64 implementation.

  Only the features currently used by HttpClient are implemented here rather than all the features of Commons Codec.

  Notes:

  - Commons Codec accepts null inputs, so this is also accepted here. This is not done in the Java 8 implementation
  - Decoding invalid input returns an empty value. The Java 8 implementation throws an exception, which is caught here
  - Commons Codec decoders accept both standard and url-safe variants of input. As this is not a requirement for HttpClient, this is NOT implemented here.
  This class is intended as in interim convenience. Any new code should use `java.util.Base64` directly.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `Base64()` Return an instance of the Base64 codec that use the regular Base64 alphabet (as opposed to the URL-safe alphabet).
    `Base64(int lineLength)` Creates a Base64 codec used for decoding and encoding in URL-unsafe mode.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `decode(byte[] base64)` Decode Base64-encoded bytes to their original form, using specifications from this codec instance
    `byte[]` | `decode(String base64)` Decode a Base64 String to its original form, using specifications from this codec instance
    `static byte[]` | `decodeBase64(byte[] base64)` Decodes Base64 data into octets.
    `static byte[]` | `decodeBase64(String base64)` Decodes a Base64 String into octets.
    `byte[]` | `encode(byte[] value)` Encode bytes to their Base64 form, using specifications from this codec instance
    `static byte[]` | `encodeBase64(byte[] base64)` Encodes binary data using the base64 algorithm but does not chunk the output.
    `static String` | `encodeBase64String(byte[] bytes)` Encodes binary data using the base64 algorithm but does not chunk the output.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### Base64

          public Base64()

      Return an instance of the Base64 codec that use the regular Base64 alphabet (as opposed to the URL-safe alphabet). Note that unlike the Commons Codec version, thus class will NOT decode characters from URL-safe alphabet.

    - #### Base64

          public Base64(int lineLength)

      Creates a Base64 codec used for decoding and encoding in URL-unsafe mode.

      As HttpClient never uses a non-zero length, this feature is not implemented here.

  - ### Method Detail

    - #### decodeBase64

          public static byte[] decodeBase64(byte[] base64)

      Decodes Base64 data into octets.

      Note: this method does NOT accept URL-safe encodings

    - #### decodeBase64

          public static byte[] decodeBase64(String base64)

      Decodes a Base64 String into octets.

      Note: this method does NOT accept URL-safe encodings

    - #### encodeBase64

          public static byte[] encodeBase64(byte[] base64)

      Encodes binary data using the base64 algorithm but does not chunk the output.

    - #### encodeBase64String

          public static String encodeBase64String(byte[] bytes)

      Encodes binary data using the base64 algorithm but does not chunk the output.

    - #### decode

          public byte[] decode(byte[] base64)

      Decode Base64-encoded bytes to their original form, using specifications from this codec instance

    - #### decode

          public byte[] decode(String base64)

      Decode a Base64 String to its original form, using specifications from this codec instance

    - #### encode

          public byte[] encode(byte[] value)

      Encode bytes to their Base64 form, using specifications from this codec instance

Copyright © 1999–2021 The Apache Software Foundation. All rights reserved.