// copy as much as possible from the sliding window to the output area int inflate_flush(ZStream z, int r) { int n; int p; int q; // local copies of source and destination pointers p = z.next_out_index; q = read; // compute number of bytes to copy as far as end of window n = ((q <= write ? write : end) - q); if (n > z.avail_out) n = z.avail_out; if (n != 0 && r == Z_BUF_ERROR) r = Z_OK; // update counters z.avail_out -= n; z.total_out += n; // update check information if (checkfn != null) z.adler = check = z._adler.adler32(check, window, q, n); // copy as far as end of window System.arraycopy(window, q, z.next_out, p, n); p += n; q += n; // see if more to copy at beginning of window if (q == end) { // wrap pointers q = 0; if (write == end) write = 0; // compute bytes to copy n = write - q; if (n > z.avail_out) n = z.avail_out; if (n != 0 && r == Z_BUF_ERROR) r = Z_OK; // update counters z.avail_out -= n; z.total_out += n; // update check information if (checkfn != null) z.adler = check = z._adler.adler32(check, window, q, n); // copy System.arraycopy(window, q, z.next_out, p, n); p += n; q += n; } // update pointers z.next_out_index = p; read = q; // done return r; }
int inflateReset(ZStream z) { if (z == null || z.istate == null) return Z_STREAM_ERROR; z.total_in = z.total_out = 0; z.msg = null; z.istate.mode = z.istate.nowrap != 0 ? BLOCKS : METHOD; z.istate.blocks.reset(z, null); return Z_OK; }
int inflateReset() { if (z == null) return Z_STREAM_ERROR; z.total_in = z.total_out = 0; z.msg = null; this.mode = HEAD; this.need_bytes = -1; this.blocks.reset(); return Z_OK; }
int inflateSync() { int n; // number of bytes to look at int p; // pointer to bytes int m; // number of marker bytes found in a row long r, w; // temporaries to save total_in and total_out // set up if (z == null) return Z_STREAM_ERROR; if (this.mode != BAD) { this.mode = BAD; this.marker = 0; } if ((n = z.avail_in) == 0) return Z_BUF_ERROR; p = z.next_in_index; m = this.marker; // search while (n != 0 && m < 4) { if (z.next_in[p] == mark[m]) { m++; } else if (z.next_in[p] != 0) { m = 0; } else { m = 4 - m; } p++; n--; } // restore z.total_in += p - z.next_in_index; z.next_in_index = p; z.avail_in = n; this.marker = m; // return no joy or set up to restart on a new block if (m != 4) { return Z_DATA_ERROR; } r = z.total_in; w = z.total_out; inflateReset(); z.total_in = r; z.total_out = w; this.mode = BLOCKS; return Z_OK; }