Base64FileDecoder.java :  » Framework » imogene » org » imogene » sync » serializer » xml » base64 » Android Open Source

Android Open Source » Framework » imogene 
imogene » org » imogene » sync » serializer » xml » base64 » Base64FileDecoder.java
// Sample program to decode a Base64 text file into a binary file.
// Author: Christian d'Heureuse (www.source-code.biz)
package org.imogene.sync.serializer.xml.base64;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;



public class Base64FileDecoder {

public static void main (String args[]) throws IOException {
   if (args.length != 2) {
      System.out.println ("Command line parameters: inputFileName outputFileName");
      System.exit (9); }
   decodeFile (args[0],args[1]); }

  /**
   * 
   * @param inputFileName
   * @param outputFileName
   * @throws IOException
   */
  private static void decodeFile(String inputFileName, String outputFileName)
      throws IOException {
    BufferedReader in = null;
    BufferedOutputStream out = null;
    try {
      in = new BufferedReader(new FileReader(inputFileName));
      out = new BufferedOutputStream(new FileOutputStream(outputFileName));
      decodeStream(in, out);
      out.flush();
    } finally {
      if (in != null)
        in.close();
      if (out != null)
        out.close();
    }
  }

  /**
   * 
   * @param in
   * @param out
   * @throws IOException
   */
  public static void decodeStream(BufferedReader in, OutputStream out)
      throws IOException {
    while (true) {
      String s = in.readLine();
      if (s == null)
        break;
      byte[] buf = Base64Coder.decode(s);
      out.write(buf);
    }
  }

} // end class Base64FileDecoder
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.