Here you can find the source of base64Encoder(byte[] src, int start, int wrapAt)
public final static String base64Encoder(byte[] src, int start, int wrapAt)
//package com.java2s; public class Main { final static String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; final static char pad = '='; public final static String base64Encoder(byte[] src, int start, int wrapAt) { return base64Encoder(src, start, src.length, wrapAt); }//from ww w .j av a2 s. c o m public final static String base64Encoder(byte[] src, int start, int length, int wrapAt) { if (src == null || src.length == 0) return null; StringBuffer encodeDst = new StringBuffer(); int lineCounter = 0; length = start + length > src.length ? src.length : start + length; while (start < length) { int buffer = 0, byteCounter; for (byteCounter = 0; byteCounter < 3 && start < length; byteCounter++, start++) buffer |= (src[start] & 0xFF) << (16 - (byteCounter << 3)); if (wrapAt > 0 && lineCounter == wrapAt) { encodeDst.append("\r\n"); lineCounter = 0; } char b1 = chars.charAt((buffer << 8) >>> 26); char b2 = chars.charAt((buffer << 14) >>> 26); char b3 = (byteCounter < 2) ? pad : chars.charAt((buffer << 20) >>> 26); char b4 = (byteCounter < 3) ? pad : chars.charAt((buffer << 26) >>> 26); encodeDst.append(b1).append(b2).append(b3).append(b4); lineCounter += 4; } return encodeDst.toString(); } }