Exemplo n.º 1
0
        /// <summary>
        /// Returns the zip file entry for the specified name, or null
        /// if not found.
        /// </summary>
        /// <param name="name"> the name of the entry </param>
        /// <returns> the zip file entry, or null if not found </returns>
        /// <exception cref="IllegalStateException"> if the zip file has been closed </exception>
        public virtual ZipEntry GetEntry(String name)
        {
            if (name == null)
            {
                throw new NullPointerException("name");
            }
            long jzentry = 0;

            lock (this)
            {
                EnsureOpen();
                jzentry = getEntry(Jzfile, Zc.GetBytes(name), true);
                if (jzentry != 0)
                {
                    ZipEntry ze = GetZipEntry(name, jzentry);
                    freeEntry(Jzfile, jzentry);
                    return(ze);
                }
            }
            return(null);
        }
Exemplo n.º 2
0
        /*
         * Writes local file (LOC) header for specified entry.
         */
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void writeLOC(XEntry xentry) throws java.io.IOException
        private void WriteLOC(XEntry xentry)
        {
            ZipEntry e        = xentry.Entry;
            int      flag     = e.Flag;
            bool     hasZip64 = false;
            int      elen     = GetExtraLen(e.Extra_Renamed);

            WriteInt(ZipConstants_Fields.LOCSIG);             // LOC header signature
            if ((flag & 8) == 8)
            {
                WriteShort(Version(e));           // version needed to extract
                WriteShort(flag);                 // general purpose bit flag
                WriteShort(e.Method_Renamed);     // compression method
                WriteInt(e.Xdostime);             // last modification time
                // store size, uncompressed size, and crc-32 in data descriptor
                // immediately following compressed entry data
                WriteInt(0);
                WriteInt(0);
                WriteInt(0);
            }
            else
            {
                if (e.Csize >= ZIP64_MAGICVAL || e.Size_Renamed >= ZIP64_MAGICVAL)
                {
                    hasZip64 = true;
                    WriteShort(45);                     // ver 4.5 for zip64
                }
                else
                {
                    WriteShort(Version(e));       // version needed to extract
                }
                WriteShort(flag);                 // general purpose bit flag
                WriteShort(e.Method_Renamed);     // compression method
                WriteInt(e.Xdostime);             // last modification time
                WriteInt(e.Crc_Renamed);          // crc-32
                if (hasZip64)
                {
                    WriteInt(ZIP64_MAGICVAL);
                    WriteInt(ZIP64_MAGICVAL);
                    elen += 20;                     //headid(2) + size(2) + size(8) + csize(8)
                }
                else
                {
                    WriteInt(e.Csize);                     // compressed size
                    WriteInt(e.Size_Renamed);              // uncompressed size
                }
            }
            sbyte[] nameBytes = Zc.GetBytes(e.Name_Renamed);
            WriteShort(nameBytes.Length);

            int elenEXTT = 0;             // info-zip extended timestamp
            int flagEXTT = 0;

            if (e.Mtime != null)
            {
                elenEXTT += 4;
                flagEXTT |= EXTT_FLAG_LMT;
            }
            if (e.Atime != null)
            {
                elenEXTT += 4;
                flagEXTT |= EXTT_FLAG_LAT;
            }
            if (e.Ctime != null)
            {
                elenEXTT += 4;
                flagEXTT |= EXTT_FLAT_CT;
            }
            if (flagEXTT != 0)
            {
                elen += (elenEXTT + 5);                 // headid(2) + size(2) + flag(1) + data
            }
            WriteShort(elen);
            WriteBytes(nameBytes, 0, nameBytes.Length);
            if (hasZip64)
            {
                WriteShort(ZIP64_EXTID);
                WriteShort(16);
                WriteLong(e.Size_Renamed);
                WriteLong(e.Csize);
            }
            if (flagEXTT != 0)
            {
                WriteShort(EXTID_EXTT);
                WriteShort(elenEXTT + 1);                 // flag + data
                WriteByte(flagEXTT);
                if (e.Mtime != null)
                {
                    WriteInt(fileTimeToUnixTime(e.Mtime));
                }
                if (e.Atime != null)
                {
                    WriteInt(fileTimeToUnixTime(e.Atime));
                }
                if (e.Ctime != null)
                {
                    WriteInt(fileTimeToUnixTime(e.Ctime));
                }
            }
            WriteExtra(e.Extra_Renamed);
            Locoff = Written;
        }