Java Byte Array to Base64 bytesToBase64(byte[] bytes)

Here you can find the source of bytesToBase64(byte[] bytes)

Description

bytes To Base

License

Apache License

Declaration

public static String bytesToBase64(byte[] bytes) 

Method Source Code

//package com.java2s;
/*// w  ww. j a va2 s.  c  o m
 * Copyright 2015 GeekSaga.
 *
 * 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.
 */

public class Main {
    private static final char sBitChars[] = { //
            'G', '5', 'g', 'D', 'j', 'P', 'V', 'M', 'R', 'Z', 'm', 'Q', 's', 'N', 'z', '-', //
            'B', 'i', '4', '_', 'k', '1', 'r', 'U', 'o', 'W', '8', 'l', '9', 'c', 'F', 'O', //
            'n', 'x', 'L', 'A', 'd', '7', 'u', 'H', '3', '0', 'S', 'a', 'f', 'C', 'h', '6', //
            'b', 'E', 'T', 'X', 't', 'y', 'q', 'J', '2', 'e', 'p', 'I', 'Y', 'K', 'v', 'w' //
    };

    public static String bytesToBase64(byte[] bytes) {
        char base64[] = new char[bytes.length];
        for (int i = 0; i < bytes.length; i++) {
            base64[i] = sBitChars[bytes[i]];
        }
        return new String(base64);
    }
}

Related

  1. byteArrayToBase64(byte[] a)
  2. bytesToBase64(byte[] bytes, int length)
  3. byteToBase64(byte[] data)