Example usage for java.util.zip GZIPInputStream GZIPInputStream

List of usage examples for java.util.zip GZIPInputStream GZIPInputStream

Introduction

In this page you can find the example usage for java.util.zip GZIPInputStream GZIPInputStream.

Prototype

public GZIPInputStream(InputStream in) throws IOException 

Source Link

Document

Creates a new input stream with a default buffer size.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.gz");
    GZIPInputStream gzin = new GZIPInputStream(fin);
    FileOutputStream fout = new FileOutputStream("a.dat");
    for (int c = gzin.read(); c != -1; c = gzin.read()) {
        fout.write(c);//  w  w w.j  a va  2 s  .c  om
    }
    fout.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String source = "s.gzip";
    GZIPInputStream in = new GZIPInputStream(new FileInputStream(source));
    String target = "outfile";
    OutputStream out = new FileOutputStream(target);
    byte[] buf = new byte[1024];
    int len;//  ww  w  .  j  av  a2s. c  o  m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String inFilename = "infile.gzip";
    GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));

    String outFilename = "outfile";
    OutputStream out = new FileOutputStream(outFilename);

    byte[] buf = new byte[1024];
    int len;/*w w w  .j  a  v  a 2  s  .c  om*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }

    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ObjectInputStream ois = new ObjectInputStream(
            new GZIPInputStream(new FileInputStream(new File("user.dat"))));

    User admin = (User) ois.readObject();
    User foo = (User) ois.readObject();//from   w ww .  j ava 2 s  . c  o  m

    ois.close();
    System.out.println("Admin = [" + admin + "]");
    System.out.println("Foo = [" + foo + "]");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;// ww  w. java 2 s.  c o m
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    int sChunk = 8192;

    String zipname = "a.txt.gz";
    String source = "a.txt";
    FileInputStream in = new FileInputStream(zipname);
    GZIPInputStream zipin = new GZIPInputStream(in);
    byte[] buffer = new byte[sChunk];
    FileOutputStream out = new FileOutputStream(source);
    int length;/*from   www . ja  v a  2  s. com*/
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
        out.write(buffer, 0, length);
    out.close();
    zipin.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    String zipname = "data.txt.gz";
    String source = "data.txt.gz";
    GZIPInputStream zipin;/*from  w ww  .  j av a2 s .co  m*/

    FileInputStream in = new FileInputStream(zipname);
    zipin = new GZIPInputStream(in);

    byte[] buffer = new byte[sChunk];
    // decompress the file
    FileOutputStream out = new FileOutputStream(source);
    int length;
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
        out.write(buffer, 0, length);
    out.close();

    zipin.close();
}

From source file:Main.java

public static void main(String[] args) throws IOException {

    FileInputStream fin = new FileInputStream(args[0]);
    GZIPInputStream gzin = new GZIPInputStream(fin);
    ReadableByteChannel in = Channels.newChannel(gzin);

    WritableByteChannel out = Channels.newChannel(System.out);
    ByteBuffer buffer = ByteBuffer.allocate(65536);
    while (in.read(buffer) != -1) {
        buffer.flip();/*  w  w w.java  2  s. c  o  m*/
        out.write(buffer);
        buffer.clear();
    }
}

From source file:MainClass.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        if (args[i].toLowerCase().endsWith(".gz")) {
            try {
                FileInputStream fin = new FileInputStream(args[i]);
                GZIPInputStream gzin = new GZIPInputStream(fin);
                FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3));
                for (int c = gzin.read(); c != -1; c = gzin.read()) {
                    fout.write(c);/*from w w w. ja v a2s. com*/
                }
                fout.close();
            } catch (IOException ex) {
                System.err.println(ex);
            }
        } else {
            System.err.println(args[i] + " does not appear to be a gzipped file.");
        }
    }
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    ServerSocket ssock = new ServerSocket(Integer.parseInt(args[0]));
    System.out.println("Listening");
    Socket sock = ssock.accept();
    GZIPInputStream zip = new GZIPInputStream(sock.getInputStream());
    while (true) {
        int c;/*from   ww  w.  j  a  v a2  s . com*/
        c = zip.read();
        if (c == -1)
            break;
        System.out.print((char) c);
    }
}