public static String encodeFromFile(String filename){
  String encodedData=null;
  Base64.InputStream bis=null;
  try {
    java.io.File file=new java.io.File(filename);
    byte[] buffer=new byte[(int)(file.length() * 2)];
    int length=0;
    int numBytes=0;
    bis=new Base64.InputStream(new java.io.BufferedInputStream(new java.io.FileInputStream(file)),Base64.ENCODE);
    while ((numBytes=bis.read(buffer,length,4096)) >= 0)     length+=numBytes;
    encodedData=new String(buffer,0,length,Base64.PREFERRED_ENCODING);
  }
 catch (  java.io.IOException e) {
    logger.error("Error encoding from file " + filename,e);
  }
 finally {
    try {
      bis.close();
    }
 catch (    Exception e) {
    }
  }
  return encodedData;
}

public static String encodeFromFile ( String filename ) { String encodedData = null ; Base64 . InputStream bis = null ; try { java . io . File file = new java . io . File ( filename ) ; byte [ ] buffer = new byte [ ( int ) ( file . length ( ) * 2 ) ] ; int length = 0 ; int numBytes = 0 ; bis = new Base64 . InputStream ( new java . io . BufferedInputStream ( new java . io . FileInputStream ( file ) ) , Base64 . ENCODE ) ; while ( ( numBytes = bis . read ( buffer , length , 4096 ) ) >= 0 ) length += numBytes ; encodedData = new String ( buffer , 0 , length , Base64 . PREFERRED_ENCODING ) ; } catch ( java . io . IOException e ) { logger . error ( "Error encoding from file " + filename , e ) ; } finally { try { bis . close ( ) ; } catch ( Exception e ) { } } return encodedData ; }
convenience method for reading a binary file and base64 - encoding it .
