Esempio n. 1
0
 public ZipFile(final File f, final String encoding, final boolean useUnicodeExtraFields)
     throws IOException {
   super();
   this.entries = new LinkedList<ZipEntry>();
   this.nameMap = new HashMap<String, LinkedList<ZipEntry>>(509);
   this.DWORD_BUF = new byte[8];
   this.WORD_BUF = new byte[4];
   this.CFH_BUF = new byte[42];
   this.SHORT_BUF = new byte[2];
   this.OFFSET_COMPARATOR =
       new Comparator<ZipEntry>() {
         public int compare(final ZipEntry e1, final ZipEntry e2) {
           if (e1 == e2) {
             return 0;
           }
           final Entry ent1 = (e1 instanceof Entry) ? ((Entry) e1) : null;
           final Entry ent2 = (e2 instanceof Entry) ? ((Entry) e2) : null;
           if (ent1 == null) {
             return 1;
           }
           if (ent2 == null) {
             return -1;
           }
           final long val =
               ent1.getOffsetEntry().headerOffset - ent2.getOffsetEntry().headerOffset;
           return (val == 0L) ? 0 : ((val < 0L) ? -1 : 1);
         }
       };
   this.archiveName = f.getAbsolutePath();
   this.encoding = encoding;
   this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
   this.useUnicodeExtraFields = useUnicodeExtraFields;
   this.archive = new RandomAccessFile(f, "r");
   boolean success = false;
   try {
     final Map<ZipEntry, NameAndComment> entriesWithoutUTF8Flag =
         this.populateFromCentralDirectory();
     this.resolveLocalFileHeaderData(entriesWithoutUTF8Flag);
     success = true;
   } finally {
     if (!success) {
       try {
         this.closed = true;
         this.archive.close();
       } catch (IOException ex) {
       }
     }
   }
 }