![JAR search and dependency download from the Maven repository](/logo.png)
com.microsoft.rest.v2.util.Base64Util Maven / Gradle / Ivy
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for
* license information.
*/
package com.microsoft.rest.v2.util;
import java.util.Base64;
/**
* Provides Base64 encoding/decoding methods.
*/
public final class Base64Util {
/**
* Encodes a byte array to base64.
* @param src the byte array to encode
* @return the base64 encoded bytes
*/
public static byte[] encode(byte[] src) {
return src == null ? null : Base64.getEncoder().encode(src);
}
/**
* Encodes a byte array to base64 URL format.
* @param src the byte array to encode
* @return the base64 URL encoded bytes
*/
public static byte[] encodeURLWithoutPadding(byte[] src) {
return src == null ? null : Base64.getUrlEncoder().withoutPadding().encode(src);
}
/**
* Encodes a byte array to a base 64 string.
* @param src the byte array to encode
* @return the base64 encoded string
*/
public static String encodeToString(byte[] src) {
return src == null ? null : Base64.getEncoder().encodeToString(src);
}
/**
* Decodes a base64 encoded byte array.
* @param encoded the byte array to decode
* @return the decoded byte array
*/
public static byte[] decode(byte[] encoded) {
return encoded == null ? null : Base64.getDecoder().decode(encoded);
}
/**
* Decodes a byte array in base64 URL format.
* @param src the byte array to decode
* @return the decoded byte array
*/
public static byte[] decodeURL(byte[] src) {
return src == null ? null : Base64.getUrlDecoder().decode(src);
}
/**
* Decodes a base64 encoded string.
* @param encoded the string to decode
* @return the decoded byte array
*/
public static byte[] decodeString(String encoded) {
return encoded == null ? null : Base64.getDecoder().decode(encoded);
}
private Base64Util() {
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy