public static byte[] decompress(byte[] data, int uncompressBufSize) {

        // mpd: new code
        byte [] inbuf = data;   // input is first assigned to full data
        int rem = data.length;
        int count = 0;
        int off = 0;

        // Create an expandable byte array to hold the decompressed data
        ByteArrayOutputStream bos = new ByteArrayOutputStream((int) (1.5 * inbuf.length));

        // Decompress the data
        byte[] outbuf = new byte[uncompressBufSize];

        while (rem > 0) {

            // Create the decompressor and give it the data to compress
            Inflater decompressor = new Inflater();
            decompressor.setInput(inbuf);

            try {
                //byte[] outbuf = new byte[uncompressBufSize];
                uncompressBufSize = outbuf.length;
                count = decompressor.inflate(outbuf, 0, uncompressBufSize);

                rem = decompressor.getRemaining();
                if (rem > 0) {
                    off += inbuf.length - rem;
                    inbuf = new byte[rem];
                    System.arraycopy(data, off, inbuf, 0, rem);
                    uncompressBufSize -= count;
                }

                bos.write(outbuf, 0, count);

            //} catch (DataFormatException e) {
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }

        try {
            bos.close();
        } catch (IOException e) {
        }

        // Get the decompressed data
        return bos.toByteArray();
    }