Java tutorial
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.util.zip.Inflater; public class Main { public static void decompress(byte[] data, int off, int len, OutputStream out) { Inflater decompresser = new Inflater(); decompresser.reset(); decompresser.setInput(data, off, len); byte[] buf = new byte[1024]; try { while (!decompresser.finished()) { int i = decompresser.inflate(buf); out.write(buf, 0, i); out.flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } finally { decompresser.end(); } } public static byte[] decompress(byte[] data, int off, int len) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(data.length); try { byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; } public static byte[] decompress(byte[] data, int off, int len, int srcLen) { byte[] output = null; Inflater decompresser = new Inflater(); decompresser.reset(); // decompresser.setInput(data); decompresser.setInput(data, off, len); ByteArrayOutputStream o = new ByteArrayOutputStream(srcLen); try { o.reset(); byte[] buf = new byte[1024]; while (!decompresser.finished()) { int i = decompresser.inflate(buf); o.write(buf, 0, i); } output = o.toByteArray(); } catch (Exception e) { throw new RuntimeException(e); } finally { try { o.close(); decompresser.end(); } catch (Exception e) { } } return output; } }