/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } return new String(outBuff, 0, e, UTF_8); }
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } return new String(outBuff, 0, e, UTF_8); }
/** * Encodes a byte array into Base64 notation. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @return encoded base64 representation of source. */ public static String encodeBytes(byte[] source, int off, int len) { final int len43 = len * 4 / 3; byte[] outBuff = new byte[len43 + ((len % 3) > 0 ? 4 : 0)]; int d = 0; int e = 0; int len2 = len - 2; for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); if (d < len) { encode3to4(source, d + off, len - d, outBuff, e); e += 4; } try { return new String(outBuff, 0, e, UTF_8); } catch (UnsupportedEncodingException uue) { return new String(outBuff, 0, e); } }