Encodes a byte array into Base64 notation. Does not GZip-compress data.

@param source
The data to convert
@return The data in Base64-encoded form
@throws NullPointerException
if source array is null
@since 1.4
544588
public static StringBuilder encodeBytes(final StringBuilder iOutput, final byte[] source) {
		if (source != null) {
			// Since we're not going to have the GZIP encoding turned on,
			// we're not going to have an java.io.IOException thrown, so
			// we should not force the user to have to catch it.
			try {
				iOutput.append(encodeBytes(source, 0, source.length, NO_OPTIONS));
			} catch (java.io.IOException ex) {
				assert false : ex.getMessage();
			}
		}
		return iOutput;
	}
767382
public static byte[] encode( byte[] dData )
    {
        if( dData == null )
        {
            throw new IllegalArgumentException( "Cannot encode null" );
        }
        byte[] eData = new byte[( ( dData.length + 2 ) / 3 ) * 4];

        int eIndex = 0;
        for( int i = 0; i < dData.length; i += 3 )
        {
            int d1;
            int d2 = 0;
            int d3 = 0;
            int e1;
            int e2;
            int e3;
            int e4;
            int pad = 0;

            d1 = dData[ i ];
            if( ( i + 1 ) < dData.length )
            {
                d2 = dData[ i + 1 ];
                if( ( i + 2 ) < dData.length )
                {
                    d3 = dData[ i + 2 ];
                }
                else
                {
                    pad = 1;
                }
            }
            else
            {
                pad = 2;
            }

            e1 = ALPHASET[ ( d1 & I6O2 ) >> 2 ];
            e2 = ALPHASET[ ( d1 & O6I2 ) << 4 | ( d2 & I4O4 ) >> 4 ];
            e3 = ALPHASET[ ( d2 & O4I4 ) << 2 | ( d3 & I2O6 ) >> 6 ];
            e4 = ALPHASET[ ( d3 & O2I6 ) ];

            eData[ eIndex++ ] = (byte) e1;
            eData[ eIndex++ ] = (byte) e2;
            eData[ eIndex++ ] = ( pad < 2 ) ? (byte) e3 : (byte) '=';
            eData[ eIndex++ ] = ( pad < 1 ) ? (byte) e4 : (byte) '=';

        }
        return eData;
    }
507773
public static byte[] fromBase64(String base64String) {

        byte[] result = null;
        if (base64String != null) {
            result = Base64.decodeBase64(base64String);
        }
        return result;
    }
882649
public static byte[] encode(final byte[] data) throws IOException {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        GZIPOutputStream gzOut = null;
        try {
            gzOut = new GZIPOutputStream(byteOut);
            gzOut.write(data);
            gzOut.close();
            byteOut.close();
            return byteOut.toByteArray();
        } finally {
            gzOut.close();
            byteOut.close();
        }
    }
618816
public byte[] encode(Map<String, String> map) throws SerializationException {
        if (map == null || map.isEmpty()) {
            return null;
        }
        UnsafeByteArrayOutputStream out = new UnsafeByteArrayOutputStream(64);
        try {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                writeString(out, entry.getKey());
                writeString(out, entry.getValue());
            }
            return out.toByteArray();
        } catch (IOException ex) {
            throw new SerializationException(ex.getMessage(), ex);
        }
    }
33170
public static String encodeUrlSafe(String source, String charset) {
		return Base64Encoder.encodeUrlSafe(source, charset);
	}
436666
public static String base64Encode(byte[] bytes) {
    if (bytes == null) {
      throw new IllegalArgumentException("Input bytes must not be null.");
    }
    if (bytes.length >= BASE64_UPPER_BOUND) {
      throw new IllegalArgumentException(
          "Input bytes length must not exceed " + BASE64_UPPER_BOUND);
    }

    // Every three bytes is encoded into four characters.
    //
    // Example:
    //           input |0 1 0 1 0 0 1 0|0 1 1 0 1 1 1 1|0 1 1 0 0 0 1 0|
    // encode grouping |0 1 0 1 0 0|1 0 0 1 1 0|1 1 1 1 0 1|1 0 0 0 1 0|
    //   encoded ascii |     U     |     m     |     9     |     i     |

    int triples = bytes.length / 3;

    // If the number of input bytes is not a multiple of three, padding characters will be added.
    if (bytes.length % 3 != 0) {
      triples += 1;
    }

    // The encoded string will have four characters for every three bytes.
    char[] encoding = new char[triples << 2];

    for (int in = 0, out = 0; in < bytes.length; in += 3, out += 4) {
      int triple = (bytes[in] & 0xff) << 16;
      if (in + 1 < bytes.length) {
        triple |= ((bytes[in + 1] & 0xff) << 8);
      }
      if (in + 2 < bytes.length) {
        triple |= (bytes[in + 2] & 0xff);
      }
      encoding[out] = BASE64_CHARS.charAt((triple >> 18) & 0x3f);
      encoding[out + 1] = BASE64_CHARS.charAt((triple >> 12) & 0x3f);
      encoding[out + 2] = BASE64_CHARS.charAt((triple >> 6) & 0x3f);
      encoding[out + 3] = BASE64_CHARS.charAt(triple & 0x3f);
    }

    // Add padding characters if needed.
    for (int i = encoding.length - (triples * 3 - bytes.length); i < encoding.length; i++) {
      encoding[i] = '=';
    }

    return String.valueOf(encoding);
  }
1272528
public static String encodeByteArray(byte[] byteArray) {
		try {
			return new String(Base64.encodeBase64(byteArray), UTF8_ENCODING);
		} catch(UnsupportedEncodingException e) {
			throw new MappingException("Could not encode byteArray to UTF8 encoding", e);
		}
	}
85811
public static byte[] encryptAES2Base64(byte[] data, byte[] key) {
        try {
            return Base64.getEncoder().encode(encryptAES(data, key));
        } catch (Exception e) {
            return null;
        }
    }
563719
public Object javaToSql(Object source)
    {
        synchronized (byteOut)
        {
            try
            {
                if (gzipOut == null)
                {
                    gzipOut = new GZIPOutputStream(uuOut);
                    objOut = new ObjectOutputStream(gzipOut);
                }

                /*
                ** Clear out the byte array
                */
                byteOut.reset();

                objOut.writeObject(source);
                objOut.flush();
                gzipOut.finish();
                gzipOut.flush();

                return (byteOut.toString());
            }
            catch (Throwable t)
            {
                throw new ConversionException(t);
            }
        }
    }
1244001
public static String encode(byte[] source, String charset) {
		return StrUtil.str(encode(source, false), charset);
	}
67540
@SuppressWarnings("AssignmentToForLoopParameter")
    public static String encode(final byte[] data) {
        final int len = data.length;
        final StringBuilder result = new StringBuilder((len / 3 + 1) * 4);
        int bte;
        int index;

        for (int i = 0; i < len; i++) {

            bte = data[i];

            // First 6 bits
            index = bte >> 2 & MASK_6;
            result.append(CHAR_TABLE.charAt(index));

            // Last 2 bits plus 4 from next byte
            index = bte << 4 & MASK_6;

            if (++i < len) {
                bte = data[i];
                index |= bte >> 4 & MASK_4;
            }
            result.append(CHAR_TABLE.charAt(index));

            // 4 + 2 from next
            if (i < len) {
                index = bte << 2 & MASK_6;
                if (++i < len) {
                    bte = data[i];
                    index |= bte >> 6 & MASK_2;
                }
                result.append(CHAR_TABLE.charAt(index));
            } else {
                i++;
                result.append(CHAR_TABLE.charAt(64));
            }
            if (i < len) {
                index = bte & MASK_6;
                result.append(CHAR_TABLE.charAt(index));
            } else {
                result.append(CHAR_TABLE.charAt(64));
            }
        }

        return result.toString();
    }
1036510
public final byte[] encode(byte[] source, int off, int len) {		
		int	len43 = len * 4 / 3;
		byte[] outBuff = new byte[ ( len43 )					  // main 4:3
								   + ( (len % 3) > 0 ? 4 : 0 ) ]; // account for padding
		int d = 0;
		int e = 0;
		int len2 = len - 2;
		int lineLength = 0;
		for (; d < len2; d+=3, e+=4) {
			encode3to4(source, d+off, 3, outBuff, e);

			lineLength += 4;
		} // end for: each piece of array

		if (d < len) {
			encode3to4(source, d+off, len - d, outBuff, e);
			e += 4;
		} // end if: some padding needed
		
		byte[] out = new byte[e];
		System.arraycopy(outBuff, 0, out, 0, e); 
		return out;
	}
1194329
@Override
	public String encodeAsString() {
		if(message.size == 0) return "";

		return new String(Base64Coder.encode(message.array, message.size));
	}
422804
public static String encodeBytes(byte[] bytes)
    {
        String ret = null;

        try
        {
            // Obfuscate the string
            if(bytes != null)
                ret = new String(Base64.encodeBase64(bytes));
        }
        catch(NoClassDefFoundError e)
        {
            ret = new String(bytes);
            System.out.println("WARNING: unable to encode: "
                +e.getClass().getName()+": "+e.getMessage());
        }

        return ret;
    }
1237703
@Override
    public String encodeBase64(byte[] value) {
        return new String(Base64.encodeBase64(value), Charsets.UTF_8);
    }
484256
public static String encode(String source, String charset) {
		return Base64Encoder.encode(source, charset);
	}