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:net.ulno.jpunch.util.Util.java

public static byte[] zip(byte[] data) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    GZIPOutputStream gz = new GZIPOutputStream(os);
    gz.write(data);//from w w w  . jav  a2  s.co  m
    gz.finish();
    return os.toByteArray();
}

From source file:Main.java

public static byte[] compress(byte[] bytes) throws IOException {
    byte[] result = null;
    ByteArrayOutputStream out = null;
    GZIPOutputStream gzip = null;
    try {//from   w  w  w.  ja  va 2s  .  com
        out = new ByteArrayOutputStream(bytes.length);
        gzip = new GZIPOutputStream(out);
        gzip.write(bytes);
        gzip.finish();
        close(gzip);
        result = out.toByteArray();
    } catch (IOException e) {
        throw e;
    } finally {
        close(gzip);
        close(out);
    }
    return result;
}

From source file:Util.java

public static byte[] compress(Object data) {
    if (data == null) {
        return null;
    }/* w  ww.  ja  va  2 s.c  o  m*/
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        GZIPOutputStream gout = new GZIPOutputStream(baos);
        ObjectOutputStream oos = new ObjectOutputStream(gout);
        oos.writeObject(data);
        oos.flush();
        gout.finish();
        return baos.toByteArray();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

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

private static byte[] GZIPCompress(byte[] requestContent) throws IOException {
    ByteArrayOutputStream compressedContent = new ByteArrayOutputStream();
    GZIPOutputStream gzipstream = new GZIPOutputStream(compressedContent);
    gzipstream.write(requestContent);//from   w  w  w .j  av a 2 s  .c o  m
    gzipstream.finish();

    // get the compressed content
    return compressedContent.toByteArray();
}

From source file:com.googlesource.gerrit.plugins.github.velocity.VelocityStaticServlet.java

private static byte[] compress(final byte[] raw) throws IOException {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final GZIPOutputStream gz = new GZIPOutputStream(out);
    gz.write(raw);//w  ww. j a v a  2  s. c  o  m
    gz.finish();
    gz.flush();
    return out.toByteArray();
}

From source file:Main.java

public static byte[] compress(byte[] src) throws IOException {

    GZIPOutputStream gzip = null;
    ByteArrayOutputStream baos = null;
    try {/*ww  w .j a v a2s  .  co m*/
        baos = new ByteArrayOutputStream();

        gzip = new GZIPOutputStream(baos);
        gzip.write(src);
        gzip.finish();

        return baos.toByteArray();

    } finally {
        if (gzip != null) {
            gzip.close();
        }
        if (baos != null) {
            baos.close();
        }
    }
}

From source file:org.apache.joshua.decoder.ff.lm.berkeley_lm.LMGrammarBerkeleyTest.java

private static void compress(FileInputStream lmFileStream, String target) throws IOException {
    try {/*  www.j a  v a 2s  .c o  m*/
        Files.createFile(Paths.get(target));
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(new FileOutputStream(target));
        IOUtils.copy(lmFileStream, gzipOutputStream);
        gzipOutputStream.finish();
    } catch (FileAlreadyExistsException fae) {
        // the file already exists, no need to recreate it
    }
}

From source file:org.apache.ode.daohib.bpel.hobj.GZipDataType.java

/**
 * Compress (using gzip algorithm) a byte array into an output stream.
 *///from www  .j  a  va2  s  .c  om
public static void gzip(byte[] content, OutputStream out) {
    try {
        GZIPOutputStream zip = new GZIPOutputStream(out);
        zip.write(content, 0, content.length);
        zip.finish();
        zip.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    }
}

From source file:Main.java

public static void gzipIt(String inputFile, String outputFile) {

    byte[] buffer = new byte[1024];

    try {/*w  w  w .  jav a2 s .  c  om*/

        GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(outputFile));

        FileInputStream in = new FileInputStream(inputFile);

        int len;
        while ((len = in.read(buffer)) > 0) {
            gzos.write(buffer, 0, len);
        }

        in.close();

        gzos.finish();
        gzos.close();

        System.out.println("Done");

    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:org.apache.juneau.rest.test.GzipTest.java

private static InputStream compress(String contents) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream(contents.length() >> 1);
    GZIPOutputStream gos = new GZIPOutputStream(baos);
    gos.write(contents.getBytes());/* www  . jav  a2s.c  o m*/
    gos.finish();
    gos.close();
    return new ByteArrayInputStream(baos.toByteArray());
}