/** * Converts a byte array into a Base64 encoded string. * * @param data bytes to encode. * @param offset which byte to start at. * @param length how many bytes to encode; padding will be added if needed. * @return base64 encoding of data; 4 chars for every 3 bytes. */ public static String encode(byte[] data, int offset, int length) { int i; int encodedLen; char[] encoded; // 4 chars for 3 bytes, run input up to a multiple of 3 encodedLen = (length + 2) / 3 * 4; encoded = new char [encodedLen]; for (i = 0, encodedLen = 0; encodedLen < encoded.length; i += 3, encodedLen += 4) { encodeQuantum(data, offset + i, length - i, encoded, encodedLen); } return new String(encoded); }
/** * Converts a byte array into a Base64 encoded string. * * @param data bytes to encode. * @param offset which byte to start at. * @param length how many bytes to encode; padding will be added if needed. * @return base64 encoding of data; 4 chars for every 3 bytes. */ public static String encode(byte[] data, int offset, int length) { int i; int encodedLen; char[] encoded; // 4 chars for 3 bytes, run input up to a multiple of 3 encodedLen = (length + 2) / 3 * 4; encoded = new char [encodedLen]; for (i = 0, encodedLen = 0; encodedLen < encoded.length; i += 3, encodedLen += 4) { encodeQuantum(data, offset + i, length - i, encoded, encodedLen); } return new String(encoded); }