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

class HelloWorld  {

	public HelloWorld() {
	}
	
	private static void printB(byte[] d, int len) {
		for (int i = 0; i < len; i++) {
			System.out.printf("%02X ", d[i]);
		}
		System.out.println();
	}

	private static void printD(byte[] d, int len) {
		for (int i = 0; i < len; i++) {
			String s = "00000000" + Integer.toString(0xFF & d[i], 2) + " ";
			System.out.print(s.substring(s.length() - 9));
		}
		System.out.println();
	}
	
	private static void printR(byte[] d, int len) {
		for (int i = 0; i < len; i++) {
			String s = "00000000" + Integer.toString(0xFF & d[i], 2);
			StringBuilder b = new StringBuilder(s.substring(s.length() - 8));
			System.out.print(b.reverse() + " ");
		}
		System.out.println();
	}

	public static void main(String[] args) throws java.lang.Exception {

		 try {
		     // Encode a String into bytes
		     String inputString = "blahblahblah";
		     byte[] input = inputString.getBytes("UTF-8");

		     System.out.println("input:");
		     HelloWorld.printB(input, input.length);
		     HelloWorld.printD(input, input.length);
		     HelloWorld.printR(input, input.length);
		     
		     // Compress the bytes
		     byte[] output = new byte[100];
		     Deflater compresser = new Deflater(
		     	Deflater.DEFAULT_COMPRESSION, true);
		     compresser.setInput(input);
		     compresser.finish();
		     int compressedDataLength = compresser.deflate(output);
		     compresser.end();

		     
		     output[0] = 0x4B;
		     output[1] = -54; //0xCA;
		     output[2] = 0x49;
		     output[3] = -52; // 0xCC;
		     output[4] = -128; //0x80;
		     output[5] = 0x63;
		     output[6] = 0x00;
		     compressedDataLength = 7;
		     
		     System.out.println("output:");
		     HelloWorld.printB(output, compressedDataLength);
		     HelloWorld.printD(output, compressedDataLength);
		     HelloWorld.printR(output, compressedDataLength);

		     // Decompress the bytes
		     Inflater decompresser = new Inflater(true);
		     decompresser.setInput(output, 0, compressedDataLength);
		     byte[] result = new byte[100];
		     int resultLength = decompresser.inflate(result);
		     decompresser.end();
		     
		     System.out.println("decompress:");
		     HelloWorld.printB(result,  resultLength);

		     // Decode the bytes into a String
		     String outputString = new String(result, 0, resultLength, "UTF-8");
		     System.out.println(outputString);
		 } catch(java.lang.IllegalArgumentException ex) {
		 	ex.printStackTrace();
		 } catch(java.io.UnsupportedEncodingException ex) {
		     // handle
		 } catch (java.util.zip.DataFormatException ex) {
		     // handle
		 }
		 
		
	}

}