Here you can find the source of encodeLast1Byte(byte bytes[])
private static String encodeLast1Byte(byte bytes[])
//package com.java2s; public class Main { private static String encodeLast1Byte(byte bytes[]) { byte lastByte = bytes[bytes.length - 1]; StringBuffer resultBuffer = new StringBuffer(); byte bufferByte = 0; bufferByte = (byte) (lastByte >> 2); resultBuffer.append(encodeBase64Byte(bufferByte)); bufferByte = (byte) ((lastByte & 0x03) << 4); resultBuffer.append(encodeBase64Byte(bufferByte)); resultBuffer.append('='); resultBuffer.append('='); return resultBuffer.toString(); }/*from ww w . jav a 2 s . com*/ private static char encodeBase64Byte(byte base64Byte) { if ((base64Byte >= 0) && (base64Byte <= 25)) { return (char) (base64Byte + 65); } else if ((base64Byte >= 26) && (base64Byte <= 51)) { return (char) (base64Byte - 26 + 97); } else if ((base64Byte >= 52) && (base64Byte <= 61)) { return (char) (base64Byte - 52 + 48); } else if (base64Byte == 62) { return '+'; } else if (base64Byte == 63) { return '/'; } else { return '0'; } } }