/* Converts an image file to a textual Base 64 representation. * Run using the command * java -classpath * %classpath%;H:\commons-codec-1.3\commons-codec-1.3.jar * Base64Encoding gittleman.gif * where gittleman.gif is the image to convert. */ import org.apache.commons.codec.binary.Base64; import java.io.*; public class Base64Encoding { public static void main(String[] args) { try { File f = new File(args[0]); byte[] me = new byte[(int)f.length()]; System.out.println("gittleman.gif length: " + f.length()); InputStream in = new FileInputStream(f); in.read(me); for(int i = 0; i<50; i++) System.out.print((char)me[i]); System.out.println(); in.close(); in = new FileInputStream(f); for(int i = 0; i<20; i++) System.out.print(Integer.toHexString(in.read()) + " "); System.out.println(); byte[] encoded = Base64.encodeBase64(me); System.out.println("Encoded length: " + encoded.length); for(int i = 0; i<50; i++) System.out.print((char)encoded[i]); System.out.println(); in.close(); }catch(Exception e) { e.printStackTrace(); } } }