Java XML Base64 Encode Decode base64FromBinary(byte[] value)

Here you can find the source of base64FromBinary(byte[] value)

Description

Convert (encode) the given binary value using Base64.

License

Apache License

Parameter

Parameter Description
value A binary value.

Exception

Parameter Description
IllegalArgumentException If the given value is null.

Return

Base64-encoded value.

Declaration

public static String base64FromBinary(byte[] value) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
/*// ww  w . ja  v a2s.co m
 * Copyright (C) 2014 Dell, Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Arrays;

import javax.xml.bind.DatatypeConverter;

public class Main {
    /**
     * Convert (encode) the given binary value using Base64.
     * 
     * @param  value                    A binary value.
     * @return                          Base64-encoded value.
     * @throws IllegalArgumentException If the given value is null.
     */
    public static String base64FromBinary(byte[] value) throws IllegalArgumentException {
        return DatatypeConverter.printBase64Binary(value);
    }

    /**
     * Convert (encode) the given binary value, beginning at the given offset and
     * consisting of the given length, using Base64.
     * 
     * @param  value                    A binary value.
     * @param  offset                   Zero-based index where data begins.
     * @param  length                   Number of bytes to encode.
     * @return                          Base64-encoded value.
     * @throws IllegalArgumentException If the given value is null.
     */
    public static String base64FromBinary(byte[] value, int offset, int length) throws IllegalArgumentException {
        return DatatypeConverter.printBase64Binary(Arrays.copyOfRange(value, offset, offset + length));
    }
}

Related

  1. base64Encode(byte[] bytes)
  2. base64Encode(byte[] bytes)
  3. base64encode(byte[] bytes, boolean pad)
  4. base64Encode(String data)
  5. base64EncodeBasicCredentials(String username, String password)
  6. base64FromString(String value)
  7. base64ToByte(String data)
  8. byteArrayToBase64String(byte[] data)
  9. BytesToBase64String(final byte[] value)