Example usage for java.util.zip Deflater setStrategy

List of usage examples for java.util.zip Deflater setStrategy

Introduction

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

Prototype

public void setStrategy(int strategy) 

Source Link

Document

Sets the compression strategy to the specified value.

Usage

From source file:prz.PRZ.java

/**
 *
 * @param bytes//from  w  ww  . ja  va2s . 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;
}