Exemplo n.º 1
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));
     }
 }
Exemplo n.º 2
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);
                }
            }
        }
        //Methods

        /// <summary>
        /// Returns 0 once the end of the stream (EOF) has been reached.
        /// Otherwise returns 1.
        /// </summary>
        public virtual int Available()
        {
            return(inf.Finished() ? 0 : 1);
        }