Пример #1
0
        public int read(byte[] b, int off, int len)
        {
            if (len == 0)
            {
                return(0);
            }
            this.z.next_out       = b;
            this.z.next_out_index = off;
            this.z.avail_out      = len;
            while (true)
            {
                if (this.z.avail_in == 0 && !this.nomoreinput)
                {
                    this.z.next_in_index = 0;
                    int count = this.bufsize;
                    if (this.maxInput > 0L)
                    {
                        if (this.TotalIn < this.maxInput)
                        {
                            count = (int)Math.Min(this.maxInput - this.TotalIn, (long)this.bufsize);
                        }
                        else
                        {
                            this.z.avail_in = -1;
                        }
                    }
                    if (this.z.avail_in != -1)
                    {
                        this.z.avail_in = SupportClass.ReadInput(this.in_Renamed, this.buf, 0, count);
                    }
                    if (this.z.avail_in == -1)
                    {
                        this.z.avail_in  = 0;
                        this.nomoreinput = true;
                    }
                }
                int num;
                if (this.compress)
                {
                    num = this.z.deflate(this.flush);
                }
                else
                {
                    num = this.z.inflate(this.flush);
                }
                if (this.nomoreinput && num == -5)
                {
                    break;
                }
                if (num != 0 && num != 1)
                {
                    goto Block_12;
                }
                if (this.nomoreinput && this.z.avail_out == len)
                {
                    return(-1);
                }
                if (this.z.avail_out <= 0 || num != 0)
                {
                    goto IL_184;
                }
            }
            return(-1);

Block_12:
            throw new ZStreamException((this.compress ? "de" : "in") + "flating: " + this.z.msg);
IL_184:
            return(len - this.z.avail_out);
        }
Пример #2
0
        public int read(byte[] b, int off, int len)
        {
            if (len == 0)
            {
                return(0);
            }
            int err;

            z.next_out       = b;
            z.next_out_index = off;
            z.avail_out      = len;
            do
            {
                if ((z.avail_in == 0) && (!nomoreinput))
                {
                    // if buffer is empty and more input is avaiable, refill it
                    z.next_in_index = 0;

                    int inToRead = bufsize;
                    if (maxInput > 0)
                    {
                        if (TotalIn < maxInput)
                        {
                            inToRead = (int)(Math.Min(maxInput - TotalIn, (long)bufsize));
                        }
                        else
                        {
                            z.avail_in = -1;
                        }
                    }
                    if (z.avail_in != -1)
                    {
                        z.avail_in = SupportClass.ReadInput(in_Renamed, buf, 0, inToRead);                         //(bufsize<z.avail_out ? bufsize : z.avail_out));
                    }
                    if (z.avail_in == -1)
                    {
                        z.avail_in  = 0;
                        nomoreinput = true;
                    }
                }
                if (compress)
                {
                    err = z.deflate(flush);
                }
                else
                {
                    err = z.inflate(flush);
                }
                if (nomoreinput && (err == zlibConst.Z_BUF_ERROR))
                {
                    return(-1);
                }
                if (err != zlibConst.Z_OK && err != zlibConst.Z_STREAM_END)
                {
                    throw new ZStreamException((compress ? "de" : "in") + "flating: " + z.msg);
                }
                if (nomoreinput && (z.avail_out == len))
                {
                    return(-1);
                }
            }while (z.avail_out > 0 && err == zlibConst.Z_OK);
            //while (z.avail_out == len && err == zlibConst.Z_OK);
            //System.err.print("("+(len-z.avail_out)+")");
            return(len - z.avail_out);
        }