public final static char[] encodeToChar(byte[] bytes, boolean lineSep)
	{
		// Check special case
		int bytes_len = bytes != null ? bytes.length : 0;
		if (bytes_len == 0)
			return new char[0];

		int eLen = (bytes_len / 3) * 3;              // Length of even 24-bits.
		int cCnt = ((bytes_len - 1) / 3 + 1) << 2;   // Returned character count
		int chars_len = cCnt + (lineSep ? (cCnt - 1) / 76 << 1 : 0); // Length of returned array
		char[] chars = new char[chars_len];

		// Encode even 24-bits
		for (int s = 0, d = 0, cc = 0; s < eLen;) {
			// Copy next three bytes into lower 24 bits of int, paying attension to sign.
			int i = (bytes[s++] & 0xff) << 16 | (bytes[s++] & 0xff) << 8 | (bytes[s++] & 0xff);

			// Encode the int into four chars
			chars[d++] = CA[(i >>> 18) & 0x3f];
			chars[d++] = CA[(i >>> 12) & 0x3f];
			chars[d++] = CA[(i >>> 6) & 0x3f];
			chars[d++] = CA[i & 0x3f];

			// Add optional line separator
			if (lineSep && ++cc == 19 && d < chars_len - 2) {
				chars[d++] = '\r';
				chars[d++] = '\n';
				cc = 0;
			}
		}

		// Pad and encode last bits if source isn't even 24 bits.
		int left = bytes_len - eLen; // 0 - 2.
		if (left > 0) {
			// Prepare the int
			int i = ((bytes[eLen] & 0xff) << 10) | (left == 2 ? ((bytes[bytes_len - 1] & 0xff) << 2) : 0);

			// Set last four chars
			chars[chars_len - 4] = CA[i >> 12];
			chars[chars_len - 3] = CA[(i >>> 6) & 0x3f];
			chars[chars_len - 2] = left == 2 ? CA[i & 0x3f] : '=';
			chars[chars_len - 1] = '=';
		}
		return chars;
	}
Encodes a raw byte array into a BASE64 <code>char[]</code> representation i accordance with RFC 2045.
@param bytes The bytes to convert. If <code>null</code> or length 0 an empty array will be returned.
@param lineSep Optional "\r\n" after 76 characters, unless end of file.<br>
No line separator will be in breach of RFC 2045 which specifies max 76 per line but will be a
little faster.
@return A BASE64 encoded array. Never <code>null</code>.
src/test/java/com/alibaba/json/test/Base64.java