Tuesday, 29 March 2016

Decoding with base-64 and un-GZIP-ing the file contents


import java.io.*;
import java.util.zip.GZIPInputStream;
import org.apache.commons.codec.binary.Base64InputStream;

public class DecodeBase64AndGzip {
  public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.println("Usage: java DecodeBase64AndGzipInflate
                            <inputFile> <outputFile>
");
        return;
    }

    int BUFFER_SIZE = 4096;
    byte[] buffer = new byte[BUFFER_SIZE];
    InputStream input = new GZIPInputStream(
            new Base64InputStream( new FileInputStream(args[0]) ));
    OutputStream output = new FileOutputStream(args[1]);

    int n = input.read(buffer, 0, BUFFER_SIZE);
    while (n >= 0) {
        output.write(buffer, 0, n);
        n = input.read(buffer, 0, BUFFER_SIZE);
    }
    input.close();
    output.close();
  }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.