Example usage for java.util.zip GZIPOutputStream finish

List of usage examples for java.util.zip GZIPOutputStream finish

Introduction

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

Prototype

public void finish() throws IOException 

Source Link

Document

Finishes writing compressed data to the output stream without closing the underlying stream.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream("outfile.gzip"));
    FileInputStream in = new FileInputStream("infilename");

    byte[] buf = new byte[1024];
    int len;/*from   w w  w. ja v  a 2  s . co m*/
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    out.finish();
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String outFilename = "outfile.gzip";
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename));

    String inFilename = "infilename";
    FileInputStream in = new FileInputStream(inFilename);

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

    out.finish();
    out.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], Integer.parseInt(args[1]));
    GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream());
    String line;/*from w ww  .ja  v  a 2 s.  c o m*/
    BufferedReader bis = new BufferedReader(new FileReader(args[2]));
    while (true) {
        line = bis.readLine();
        if (line == null)
            break;
        line = line + "\n";
        zip.write(line.getBytes(), 0, line.length());
    }
    zip.finish();
    zip.close();
    sock.close();
}

From source file:CompRcv.java

public static void main(String[] args) throws Exception {
    Socket sock = new Socket(args[0], Integer.parseInt(args[1]));
    GZIPOutputStream zip = new GZIPOutputStream(sock.getOutputStream());
    String line;/*  w ww  .ja v  a  2 s  .  com*/
    BufferedReader bis = new BufferedReader(new FileReader(args[2]));
    while (true) {
        try {
            line = bis.readLine();
            if (line == null)
                break;
            line = line + "\n";
            zip.write(line.getBytes(), 0, line.length());
        } catch (Exception e) {
            break;
        }
    }
    zip.finish();
    zip.close();
    sock.close();
}

From source file:Main.java

public static final byte[] compress(byte[] val) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(val.length);
    GZIPOutputStream gos = new GZIPOutputStream(bos);
    gos.write(val, 0, val.length);
    gos.finish();
    gos.close();/*from  ww  w.j a v  a2  s  . co  m*/

    // store it and set compression flag
    return bos.toByteArray();
}

From source file:Main.java

public static byte[] gzip(byte[] data) {
    byte[] b = null;
    try {//from   ww  w.j ava2  s. c  o  m
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GZIPOutputStream gzip = new GZIPOutputStream(bos);
        gzip.write(data);
        gzip.finish();
        gzip.close();

        b = bos.toByteArray();
        bos.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return b;
}

From source file:Main.java

public static byte[] compressInGzip(byte[] originalData, int offset, int length) throws Exception {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GZIPOutputStream gzipOutStream = new GZIPOutputStream(bos);
    gzipOutStream.write(originalData, offset, length);
    gzipOutStream.finish();
    gzipOutStream.flush();/*from  w  w  w.  j  a v  a2  s  . c  o  m*/
    gzipOutStream.close();
    byte[] compressData = bos.toByteArray();
    bos.close();

    return compressData;
}

From source file:Main.java

public static final byte[] compress(byte[] bytes) {
    if (bytes == null) {
        throw new NullPointerException("byte[] is NULL !");
    }/*from www  .ja va2  s . co m*/
    ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
    try {
        GZIPOutputStream gzip = new GZIPOutputStream(bos);
        gzip.write(bytes, 0, bytes.length);
        gzip.finish();
        byte[] fewerBytes = bos.toByteArray();
        gzip.close();
        bos.close();
        gzip = null;
        bos = null;
        return fewerBytes;
    } catch (IOException e) {
        return null;
    }
}

From source file:Main.java

public static void writeGZipCompressedObject(Object o, OutputStream out) throws IOException {
    GZIPOutputStream gos = new GZIPOutputStream(out);
    ObjectOutputStream oos = new ObjectOutputStream(gos);
    oos.writeObject(o);/*from   ww  w.  j  av  a2  s.  co  m*/
    oos.flush();
    gos.finish();
}

From source file:com.eviware.soapui.impl.wsdl.support.CompressedStringSupport.java

public static void setString(CompressedStringConfig compressedStringConfig, String value) {
    synchronized (compressedStringConfig) {
        long limit = SoapUI.getSettings().getLong(WsdlSettings.COMPRESSION_LIMIT, 0);
        if (limit > 0 && value.length() >= limit) {
            try {
                ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
                GZIPOutputStream out = new GZIPOutputStream(byteOut);
                out.write(value.getBytes());
                out.finish();
                value = new String(Base64.encodeBase64(byteOut.toByteArray()));
                compressedStringConfig.setCompression("gzip");
            } catch (IOException e) {
                SoapUI.logError(e);//from   w ww  . j  ava2 s .co m
                compressedStringConfig.unsetCompression();
            }
        } else if (compressedStringConfig.isSetCompression()) {
            compressedStringConfig.unsetCompression();
        }

        compressedStringConfig.setStringValue(value);
    }
}