public ByteArrayOutputStream decompress( InputStream compressedIn, int expectedDecompressedLength, boolean noWrap ) throws IOException {

    	byte [] compressedBytes = convertInputStreamToByteArray( compressedIn );

        ByteArrayOutputStream decompressedBOS = new ByteArrayOutputStream();

    	byte [] tempDecompressedBytes = new byte[ 0x10000 ];

    	int totalDecompressed = 0;
        int offset = 0;

        try {
        	while ( offset < compressedBytes.length && totalDecompressed < expectedDecompressedLength ) {

        		if ( !noWrap && compressedBytes [ offset ] != 0x78 ) {
        			break;
        		}

                Inflater inflater = new Inflater( noWrap );

                inflater.setInput( compressedBytes, offset, compressedBytes.length - offset );

        		int nDecompressed = inflater.inflate( tempDecompressedBytes );

        		if ( nDecompressed == 0 ) {
        			break;
        		}

        		totalDecompressed += nDecompressed;

        		decompressedBOS.write( tempDecompressedBytes, 0, nDecompressed );

        		offset += inflater.getTotalIn();//increment total compressed bytes consumed
        	}
        }
        catch ( DataFormatException e ) {
        	throw new IOException( e.getMessage() );
        }

        return decompressedBOS;
    }
TODO make this more memory efficient!!
GPL/DMG/src/dmg/java/mobiledevices/dmg/zlib/ZLIB.java