Package org.apache.hc.client5.http.utils
Class Base64
java.lang.Object
org.apache.hc.client5.http.utils.Base64
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.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
decode
(byte[] base64) Decode Base64-encoded bytes to their original form, using specifications from this codec instancebyte[]
Decode a Base64 String to its original form, using specifications from this codec instancestatic 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 instancestatic 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.
-
Field Details
-
CODEC
-
EMPTY_BYTES
private static final byte[] EMPTY_BYTES
-
-
Constructor Details
-
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 Details
-
decodeBase64
public static byte[] decodeBase64(byte[] base64) Decodes Base64 data into octets.Note: this method does NOT accept URL-safe encodings
-
decodeBase64
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
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
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
-