/* package whatever; // don't place package name! */

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import java.io.ByteArrayOutputStream;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static final String encoding = "UTF-8";

    public static void main (String[] args) throws Exception {
        String s = "123456789 a s d f g h j k l ; ' q w e r t y u i o p [ ] \\ 1 2 3 4 5 6 7 8 9 0 - = as df gh jk l; zx cv bn m, ./ qw er ty ui op []";
        s += "qwe rty uio p[] asd fgh jkl zxc vbn m,. 123 456 789 1234 5678 90-= qwer tyui op[] asdf ghjk l;zx cvbn m,./";
        s += "12345 67890 qwert yuiop asdfg hjklz xcvbn m,khg er xcgvdst 453 gd fyrt634 5 dg e653 545u7r ydf dgfsd fsart sdgdsg";

        String compressed = compress(s);
        System.out.println("Original_String_Length = " + s.length());
        System.out.println("Compressed_String_Length = " + compressed.length());

        String decompressed = decompress(decodeBase64(compressed));
        System.out.println("Decompressed_String_Length = " + decompressed.length() + " == Original_String_Length (" + s.length() + ")");
        System.out.println("Original_String == Decompressed_String = " + (s.equals(decompressed) ? "True" : "False"));
    }

    public static String compress(String str) throws Exception {
        byte[] bytes = str.getBytes(encoding);
        Deflater deflater = new Deflater();
        deflater.setInput(bytes);
        deflater.finish();
        ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);
        byte[] buffer = new byte[1024];
        while(!deflater.finished()) {
            int count = deflater.deflate(buffer);
            bos.write(buffer, 0, count);
        }
        bos.close();
        byte[] output = bos.toByteArray();
        return encodeBase64(output);
    }

    public static String decompress(byte[] bytes) throws Exception {
        Inflater inflater = new Inflater();
        inflater.setInput(bytes);
        ByteArrayOutputStream bos = new ByteArrayOutputStream(bytes.length);
        byte[] buffer = new byte[1024];
        while (!inflater.finished()) {
            int count = inflater.inflate(buffer);
            bos.write(buffer, 0, count);
        }
        bos.close();
        byte[] output = bos.toByteArray();
        return new String(output);
    }

    public static String encodeBase64(byte[] bytes) throws Exception {
        BASE64Encoder base64Encoder = new BASE64Encoder();
        return base64Encoder.encodeBuffer(bytes).replace("\r\n", "").replace("\n", "");
    }

    public static byte[] decodeBase64(String str) throws Exception {
        BASE64Decoder base64Decoder = new BASE64Decoder();
        return base64Decoder.decodeBuffer(str);
    }
}