public override void Write(System.Byte[] b1, int off, int len) { if (len == 0) { return; } int err; byte[] b = new byte[b1.Length]; System.Array.Copy(b1, 0, b, 0, b1.Length); z.next_in = b; z.next_in_index = off; z.avail_in = len; do { z.next_out = buf; z.next_out_index = 0; z.avail_out = bufsize; if (compress) { err = z.deflate(flush_Renamed_Field); } else { err = z.inflate(flush_Renamed_Field); } if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END) { if (err == zlibConst.Z_NEED_DICT & !this.compress) { z.inflateSetDictionary(this.dictionary, this.dictionary.Length); err = z.inflate(flush_Renamed_Field); if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END) { throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg); } } else { throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg); } } out_Renamed.Write(buf, 0, bufsize - z.avail_out); }while (z.avail_in > 0 || z.avail_out == 0); }
public static void main(String[] arg) { int err; int comprLen = 40000; int uncomprLen = comprLen; byte[] uncompr = new byte[uncomprLen]; byte[] compr = new byte[comprLen]; long dictId; ZStream c_stream = new ZStream(); err = c_stream.deflateInit(JZlib.Z_BEST_COMPRESSION); CHECK_ERR(c_stream, err, "deflateInit"); err = c_stream.deflateSetDictionary(dictionary, dictionary.Length); CHECK_ERR(c_stream, err, "deflateSetDictionary"); dictId = c_stream.adler; c_stream.next_out = compr; c_stream.next_out_index = 0; c_stream.avail_out = comprLen; c_stream.next_in = hello; c_stream.next_in_index = 0; c_stream.avail_in = hello.Length; err = c_stream.deflate(JZlib.Z_FINISH); if (err != JZlib.Z_STREAM_END) { java.lang.SystemJ.outJ.println("deflate should report Z_STREAM_END"); java.lang.SystemJ.exit(1); } err = c_stream.deflateEnd(); CHECK_ERR(c_stream, err, "deflateEnd"); ZStream d_stream = new ZStream(); d_stream.next_in = compr; d_stream.next_in_index = 0; d_stream.avail_in = comprLen; err = d_stream.inflateInit(); CHECK_ERR(d_stream, err, "inflateInit"); d_stream.next_out = uncompr; d_stream.next_out_index = 0; d_stream.avail_out = uncomprLen; while (true) { err = d_stream.inflate(JZlib.Z_NO_FLUSH); if (err == JZlib.Z_STREAM_END) { break; } if (err == JZlib.Z_NEED_DICT) { if ((int)d_stream.adler != (int)dictId) { java.lang.SystemJ.outJ.println("unexpected dictionary"); java.lang.SystemJ.exit(1); } err = d_stream.inflateSetDictionary(dictionary, dictionary.Length); } CHECK_ERR(d_stream, err, "inflate with dict"); } err = d_stream.inflateEnd(); CHECK_ERR(d_stream, err, "inflateEnd"); int j = 0; for (; j < uncompr.Length; j++) { if (uncompr[j] == 0) { break; } } java.lang.SystemJ.outJ.println("after inflateSync(): hel" + new java.lang.StringJ(uncompr, 0, j)); }