Exemple #1
0
        /// <summary>
        /// Returns an input stream for reading the contents of the specified
        /// zip file entry.
        ///
        /// <para> Closing this ZIP file will, in turn, close all input
        /// streams that have been returned by invocations of this method.
        ///
        /// </para>
        /// </summary>
        /// <param name="entry"> the zip file entry </param>
        /// <returns> the input stream for reading the contents of the specified
        /// zip file entry. </returns>
        /// <exception cref="ZipException"> if a ZIP format error has occurred </exception>
        /// <exception cref="IOException"> if an I/O error has occurred </exception>
        /// <exception cref="IllegalStateException"> if the zip file has been closed </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public java.io.InputStream getInputStream(ZipEntry entry) throws java.io.IOException
        public virtual InputStream GetInputStream(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new NullPointerException("entry");
            }
            long jzentry           = 0;
            ZipFileInputStream @in = null;

            lock (this)
            {
                EnsureOpen();
                if (!Zc.UTF8 && (entry.Flag & EFS) != 0)
                {
                    jzentry = getEntry(Jzfile, Zc.GetBytesUTF8(entry.Name_Renamed), false);
                }
                else
                {
                    jzentry = getEntry(Jzfile, Zc.GetBytes(entry.Name_Renamed), false);
                }
                if (jzentry == 0)
                {
                    return(null);
                }
                @in = new ZipFileInputStream(this, jzentry);

                switch (getEntryMethod(jzentry))
                {
                case STORED:
                    lock (Streams)
                    {
                        Streams[@in] = null;
                    }
                    return(@in);

                case DEFLATED:
                    // MORE: Compute good size for inflater stream:
                    long size = getEntrySize(jzentry) + 2;                     // Inflater likes a bit of slack
                    if (size > 65536)
                    {
                        size = 8192;
                    }
                    if (size <= 0)
                    {
                        size = 4096;
                    }
                    Inflater    inf = Inflater;
                    InputStream @is = new ZipFileInflaterInputStream(this, @in, inf, (int)size);
                    lock (Streams)
                    {
                        Streams[@is] = inf;
                    }
                    return(@is);

                default:
                    throw new ZipException("invalid compression method");
                }
            }
        }
Exemple #2
0
 internal ZipFileInflaterInputStream(ZipFile outerInstance, ZipFileInputStream zfin, Inflater inf, int size) : base(zfin, inf, size)
 {
     this.OuterInstance = outerInstance;
     this.Zfin          = zfin;
 }