jodd-core/src/main/java/jodd/util/Base64.java
public static char[] encodeToChar(final byte[] arr, final boolean lineSeparator) {
		int len = arr != null ? arr.length : 0;
		if (len == 0) {
			return new char[0];
		}

		int evenlen = (len / 3) * 3;
		int cnt = ((len - 1) / 3 + 1) << 2;
		int destLen = cnt + (lineSeparator ? (cnt - 1) / 76 << 1 : 0);
		char[] dest = new char[destLen];

		for (int s = 0, d = 0, cc = 0; s < evenlen;) {
			int i = (arr[s++] & 0xff) << 16 | (arr[s++] & 0xff) << 8 | (arr[s++] & 0xff);

			dest[d++] = CHARS[(i >>> 18) & 0x3f];
			dest[d++] = CHARS[(i >>> 12) & 0x3f];
			dest[d++] = CHARS[(i >>> 6) & 0x3f];
			dest[d++] = CHARS[i & 0x3f];

			if (lineSeparator && (++cc == 19) && (d < (destLen - 2))) {
				dest[d++] = '\r';
				dest[d++] = '\n';
				cc = 0;
			}
		}

		int left = len - evenlen; // 0 - 2.
		if (left > 0) {
			int i = ((arr[evenlen] & 0xff) << 10) | (left == 2 ? ((arr[len - 1] & 0xff) << 2) : 0);

			dest[destLen - 4] = CHARS[i >> 12];
			dest[destLen - 3] = CHARS[(i >>> 6) & 0x3f];
			dest[destLen - 2] = left == 2 ? CHARS[i & 0x3f] : '=';
			dest[destLen - 1] = '=';
		}
		return dest;
	}
public static char[] encodeToChar(final byte[] arr, final boolean lineSeparator) {
		int len = arr != null ? arr.length : 0;
		if (len == 0) {
			return new char[0];
		}

		int evenlen = (len / 3) * 3;
		int cnt = ((len - 1) / 3 + 1) << 2;
		int destLen = cnt + (lineSeparator ? (cnt - 1) / 76 << 1 : 0);
		char[] dest = new char[destLen];

		for (int s = 0, d = 0, cc = 0; s < evenlen;) {
			int i = (arr[s++] & 0xff) << 16 | (arr[s++] & 0xff) << 8 | (arr[s++] & 0xff);

			dest[d++] = CHARS[(i >>> 18) & 0x3f];
			dest[d++] = CHARS[(i >>> 12) & 0x3f];
			dest[d++] = CHARS[(i >>> 6) & 0x3f];
			dest[d++] = CHARS[i & 0x3f];

			if (lineSeparator && (++cc == 19) && (d < (destLen - 2))) {
				dest[d++] = '\r';
				dest[d++] = '\n';
				cc = 0;
			}
		}

		int left = len - evenlen; // 0 - 2.
		if (left > 0) {
			int i = ((arr[evenlen] & 0xff) << 10) | (left == 2 ? ((arr[len - 1] & 0xff) << 2) : 0);

			dest[destLen - 4] = CHARS[i >> 12];
			dest[destLen - 3] = CHARS[(i >>> 6) & 0x3f];
			dest[destLen - 2] = left == 2 ? CHARS[i & 0x3f] : '=';
			dest[destLen - 1] = '=';
		}
		return dest;
	}
public static char [ ] encodeToChar ( final byte [ ] arr , final boolean lineSeparator ) { int len = arr != null ? arr . length : 0 ; if ( len == 0 ) { return new char [ 0 ] ; } int evenlen = ( len / 3 ) * 3 ; int cnt = ( ( len - 1 ) / 3 + 1 ) << 2 ; int destLen = cnt + ( lineSeparator ? ( cnt - 1 ) / 76 << 1 : 0 ) ; char [ ] dest = new char [ destLen ] ; for ( int s = 0 , d = 0 , cc = 0 ; s < evenlen ; ) { int i = ( arr [ s ++ ] & 0xff ) << 16 | ( arr [ s ++ ] & 0xff ) << 8 | ( arr [ s ++ ] & 0xff ) ; dest [ d ++ ] = CHARS [ ( i >>> 18 ) & 0x3f ] ; dest [ d ++ ] = CHARS [ ( i >>> 12 ) & 0x3f ] ; dest [ d ++ ] = CHARS [ ( i >>> 6 ) & 0x3f ] ; dest [ d ++ ] = CHARS [ i & 0x3f ] ; if ( lineSeparator && ( ++ cc == 19 ) && ( d < ( destLen - 2 ) ) ) { dest [ d ++ ] = ' ' ; dest [ d ++ ] = ' ' ; cc = 0 ; } } int left = len - evenlen ; // 0 - 2. if ( left > 0 ) { int i = ( ( arr [ evenlen ] & 0xff ) << 10 ) | ( left == 2 ? ( ( arr [ len - 1 ] & 0xff ) << 2 ) : 0 ) ; dest [ destLen - 4 ] = CHARS [ i >> 12 ] ; dest [ destLen - 3 ] = CHARS [ ( i >>> 6 ) & 0x3f ] ; dest [ destLen - 2 ] = left == 2 ? CHARS [ i & 0x3f ] : ' ' ; dest [ destLen - 1 ] = ' ' ; } return dest ; }
Encodes a raw byte array into a BASE64 <code>char[]</code>.
@param lineSeparator optional CRLF after 76 chars, unless EOF.
Encodes a raw byte array into a BASE64 <code > char [] < / code > .