Here you can find the source of encodeBase64(String data)
Parameter | Description |
---|---|
data | a String to encode. |
public static String encodeBase64(String data)
//package com.java2s; /*//from w w w .j ava 2 s .co m * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ import java.io.UnsupportedEncodingException; public class Main { /** * Encodes a String as a base64 String. * * @param data a String to encode. * @return a base64 encoded String. */ public static String encodeBase64(String data) { byte[] bytes = null; try { bytes = data.getBytes("UTF-8"); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } return encodeBase64(bytes); } /** * Encodes a byte array into a base64 String. * * @param data a byte array to encode. * @return a base64 encode String. */ public static String encodeBase64(byte[] data) { // Encode the String. We pass in a flag to specify that line // breaks not be added. This is consistent with our previous base64 // implementation. Section 2.1 of 3548 (base64 spec) also specifies // no line breaks by default. return (java.util.Base64.getEncoder().encodeToString(data)); //return org.jivesoftware.util.Base64.encodeBytes(data, org.jivesoftware.util.Base64.DONT_BREAK_LINES); } }