Base64 { public static String encodeBytes( byte[] source ) { String encoded = null; try { encoded = encodeBytes(source, 0, source.length, NO_OPTIONS); } catch (java.io.IOException ex) { assert false : ex.getMessage(); } assert encoded != null; return encoded; } private  Base64(); static void encode( java.nio.ByteBuffer raw, java.nio.ByteBuffer encoded ); static void encode( java.nio.ByteBuffer raw, java.nio.CharBuffer encoded ); static String encodeObject( java.io.Serializable serializableObject ); static String encodeObject( java.io.Serializable serializableObject, int options ); static String encodeBytes( byte[] source ); static String encodeBytes( byte[] source, int options ); static String encodeBytes( byte[] source, int off, int len ); static String encodeBytes( byte[] source, int off, int len, int options ); static byte[] encodeBytesToBytes( byte[] source ); static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ); static byte[] decode( byte[] source ); static byte[] decode( byte[] source, int off, int len, int options ); static byte[] decode( String s ); static byte[] decode( String s, int options ); static Object decodeToObject( String encodedObject ); static Object decodeToObject( 
			String encodedObject, int options, final ClassLoader loader ); static void encodeToFile( byte[] dataToEncode, String filename ); static void decodeToFile( String dataToDecode, String filename ); static byte[] decodeFromFile( String filename ); static String encodeFromFile( String filename ); static void encodeFileToFile( String infile, String outfile ); static void decodeFileToFile( String infile, String outfile ); final static int NO_OPTIONS; final static int ENCODE; final static int DECODE; final static int GZIP; final static int DONT_GUNZIP; final static int DO_BREAK_LINES; final static int URL_SAFE; final static int ORDERED; final static int NO_PADDING; }
@Test public void testEncodeBytesRecognizesNoPaddingOption() throws IOException { String result = Base64.encodeBytes(input, Base64.ENCODE | Base64.URL_SAFE); int excessBytes = input.length % 3; int expectedLength = (1 + (excessBytes > 0 ? 1 : 0)) * 4; assertThat(result.length(), is(expectedLength)); if (input.length % 3 > 0) { assertTrue(result.endsWith("=")); } result = Base64.encodeBytes(input, Base64.ENCODE | Base64.URL_SAFE | Base64.NO_PADDING); assertFalse(result.endsWith("=")); expectedLength = 4 + (excessBytes > 0 ? excessBytes + 1 : 0); assertThat(result.length(), is(expectedLength)); }