base64 Encode using sun.misc.BASE64Encoder - Java java.lang

Java examples for java.lang:String Base64

Description

base64 Encode using sun.misc.BASE64Encoder

Demo Code


//package com.java2s;

import sun.misc.BASE64Encoder;

import java.io.UnsupportedEncodingException;

public class Main {
    public static void main(String[] argv) throws Exception {
        byte[] input = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(base64Encode(input));
    }/*  w w w  . j  av  a 2s.  co  m*/

    public static String base64Encode(String input, String charset) {
        try {
            return base64Encode(input.getBytes(charset));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    public static String base64Encode(byte[] input) {
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encode(input);
    }
}

Related Tutorials