/// <summary>
        /// Decompresses data into the byte array
        /// </summary>
        /// <param name ="b">
        /// the array to read and decompress data into
        /// </param>
        /// <param name ="off">
        /// the offset indicating where the data should be placed
        /// </param>
        /// <param name ="len">
        /// the number of bytes to decompress
        /// </param>
        public override int Read(byte[] b, int off, int len)
        {
            for (;;)
            {
                int count;
                try {
                    count = inf.Inflate(b, off, len);
                } catch (Exception dfe) {
                    throw new Exception(dfe.ToString());
                }

                if (count > 0)
                {
                    return(count);
                }

                if (inf.NeedsDictionary())
                {
                    throw new Exception("Need a dictionary");
                }
                else if (inf.Finished())
                {
                    return(-1);
                }
                else if (inf.NeedsInput())
                {
                    Fill();
                }
                else
                {
                    throw new Exception("Don't know what to do");
                }
            }
        }
示例#2
0
 private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length)
 {
     try
     {
         do
         {
             int read = inflater.Inflate(buffer, offset, length);
             if (read <= 0)
             {
                 if (inflater.Finished())
                 {
                     throw new EOFException();
                 }
                 if (inflater.NeedsInput())
                 {
                     refillInflater(inflater);
                 }
                 else
                 {
                     throw new IOException("Can't inflate " + length + " bytes");
                 }
             }
             else
             {
                 offset += read;
                 length -= read;
             }
         } while (length > 0);
     }
     catch (DataFormatException ex)
     {
         throw (IOException)(new IOException("inflate error").InitCause(ex));
     }
 }
示例#3
0
        /// <summary>
        /// Flushes this output stream, forcing any pending buffered output bytes to be
        /// written.
        /// </summary>
        /// <exception cref="IOException"> if an I/O error occurs or this stream is already
        /// closed </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void flush() throws java.io.IOException
        public override void Flush()
        {
            EnsureOpen();

            // Finish decompressing and writing pending output data
            if (!Inf.Finished())
            {
                try
                {
                    while (!Inf.Finished() && !Inf.NeedsInput())
                    {
                        int n;

                        // Decompress pending output data
                        n = Inf.Inflate(Buf, 0, Buf.Length);
                        if (n < 1)
                        {
                            break;
                        }

                        // Write the uncompressed output data block
                        @out.Write(Buf, 0, n);
                    }
                    base.Flush();
                }
                catch (DataFormatException ex)
                {
                    // Improperly formatted compressed (ZIP) data
                    String msg = ex.Message;
                    if (msg == null)
                    {
                        msg = "Invalid ZLIB data format";
                    }
                    throw new ZipException(msg);
                }
            }
        }