package ee.aktors.beantimer.compression;

import java.io.*;
import java.util.zip.Deflater;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;

/**
 *
 */
public class Compressor {

    public static final int BUFFER_SIZE = 512;
    public static final int COMPRESSION_LEVEL = 1;

    public static String decompress(byte[] data) throws Exception {
        InputStream in = new ByteArrayInputStream(data);
        InflaterInputStream ini = new InflaterInputStream(in);
        ByteArrayOutputStream bout = new ByteArrayOutputStream(BUFFER_SIZE);
        int b;
        while ((b = ini.read()) != -1) {
            bout.write(b);
        }
        ini.close();
        bout.close();
        return new String(bout.toByteArray(), "UTF-8");
    }

    public static byte[] compressData(byte[] data) throws Exception {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DeflaterOutputStream dos = new DeflaterOutputStream(baos, new Deflater(COMPRESSION_LEVEL));
        dos.write(data);
        dos.flush();
        dos.close();

        return baos.toByteArray();
    }

}

@@ -873,19 +873,36 @@
 Stream b
-aos
+yteArrayOutputStream
  = new B
@@ -955,18 +955,35 @@
 Stream d
-os
+eflaterOutputStream
  = new D
@@ -1003,19 +1003,36 @@
 Stream(b
-aos
+yteArrayOutputStream
 , new De
@@ -1068,18 +1068,35 @@
        d
-os
+eflaterOutputStream
 .write(d
@@ -1114,31 +1114,65 @@
    d
-os.flush();%0A        dos
+eflaterOutputStream.flush();%0A        deflaterOutputStream
 .clo
@@ -1198,11 +1198,28 @@
 rn b
-aos
+yteArrayOutputStream
 .toB

Improve naming