Example usage for java.util.zip DeflaterOutputStream finish

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

Introduction

In this page you can find the example usage for java.util.zip DeflaterOutputStream 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:org.apache.tez.common.TezCommonUtils.java

@Private
public static ByteString compressByteArrayToByteString(byte[] inBytes, Deflater deflater) throws IOException {
    deflater.reset();/*  w ww  . ja  v a2s.co m*/
    ByteString.Output os = ByteString.newOutput();
    DeflaterOutputStream compressOs = null;
    try {
        compressOs = new DeflaterOutputStream(os, deflater);
        compressOs.write(inBytes);
        compressOs.finish();
        ByteString byteString = os.toByteString();
        return byteString;
    } finally {
        if (compressOs != null) {
            compressOs.close();
        }
    }
}

From source file:org.bimserver.plugins.classloaders.JarClassLoader.java

private void addDataToMap(JarInputStream jarInputStream, JarEntry entry) throws IOException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(byteArrayOutputStream);
    IOUtils.copy(jarInputStream, deflaterOutputStream);
    deflaterOutputStream.finish();
    map.put(entry.getName(), byteArrayOutputStream.toByteArray());
}

From source file:org.fejoa.library.messages.ZipEnvelope.java

static public byte[] zip(byte[] data, boolean isRawData) throws JSONException, IOException {
    JSONObject object = new JSONObject();
    object.put(Envelope.PACK_TYPE_KEY, ZIP_TYPE);
    if (isRawData)
        object.put(Envelope.CONTAINS_DATA_KEY, 1);
    object.put(ZIP_FORMAT_KEY, ZIP_FORMAT);
    String header = object.toString() + "\n";

    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    outStream.write(header.getBytes());//from   ww  w.j a  v  a 2 s  . co  m
    DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(outStream);
    deflaterOutputStream.write(data);
    deflaterOutputStream.finish();
    outStream.close();
    return outStream.toByteArray();
}

From source file:prz.PRZ.java

/**
 *
 * @param bytes/*from   www .  ja  v  a2  s.  c  o  m*/
 * @return
 */
public static byte[] huffman_test(byte[] bytes) {
    Deflater d = new Deflater(9, true);
    d.setStrategy(Deflater.HUFFMAN_ONLY);
    DeflaterOutputStream dfos;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        dfos = new DeflaterOutputStream(baos, d);
        dfos.write(bytes);
        dfos.finish();
        byte[] y = baos.toByteArray();
        System.out.println("HUFF-> BitLength:" + (bytes.length * 8) + "| BestLength: " + (y.length * 8)
                + "| Ratio: " + ((double) y.length / (bytes.length)));
        return y;
    } catch (IOException ex) {
        Logger.getLogger(PRZ.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:prz.PRZ.java

/**
 *
 * @param bytes/*from www  . j  ava  2s. co  m*/
 * @return
 */
public static byte[] deflate_test(byte[] bytes) {
    Deflater d = new Deflater(9, true);
    DeflaterOutputStream dfos;
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        dfos = new DeflaterOutputStream(baos, d);
        dfos.write(bytes);
        dfos.finish();
        byte[] y = baos.toByteArray();
        System.out.println("LZHF-> BitLength:" + (bytes.length * 8) + "| BestLength: " + (y.length * 8)
                + "| Ratio: " + ((double) y.length / (bytes.length)));
        return y;
    } catch (IOException ex) {
        Logger.getLogger(PRZ.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}