Ejemplo n.º 1
0
 private Map<ZipEntry, NameAndComment> populateFromCentralDirectory() throws IOException {
   final HashMap<ZipEntry, NameAndComment> noUTF8Flag = new HashMap<ZipEntry, NameAndComment>();
   this.positionAtCentralDirectory();
   this.archive.readFully(this.WORD_BUF);
   long sig = ZipLong.getValue(this.WORD_BUF);
   if (sig != ZipFile.CFH_SIG && this.startsWithLocalFileHeader()) {
     throw new IOException("central directory is empty, can't expand corrupt archive.");
   }
   while (sig == ZipFile.CFH_SIG) {
     this.readCentralDirectoryEntry(noUTF8Flag);
     this.archive.readFully(this.WORD_BUF);
     sig = ZipLong.getValue(this.WORD_BUF);
   }
   return noUTF8Flag;
 }
Ejemplo n.º 2
0
 private void readCentralDirectoryEntry(final Map<ZipEntry, NameAndComment> noUTF8Flag)
     throws IOException {
   this.archive.readFully(this.CFH_BUF);
   int off = 0;
   final OffsetEntry offset = new OffsetEntry();
   final Entry ze = new Entry(offset);
   final int versionMadeBy = ZipShort.getValue(this.CFH_BUF, off);
   off += 2;
   ze.setPlatform(versionMadeBy >> 8 & 0xF);
   off += 2;
   final GeneralPurposeBit gpFlag = GeneralPurposeBit.parse(this.CFH_BUF, off);
   final boolean hasUTF8Flag = gpFlag.usesUTF8ForNames();
   final ZipEncoding entryEncoding =
       hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : this.zipEncoding;
   ze.setGeneralPurposeBit(gpFlag);
   off += 2;
   ze.setMethod(ZipShort.getValue(this.CFH_BUF, off));
   off += 2;
   final long time = ZipUtil.dosToJavaTime(ZipLong.getValue(this.CFH_BUF, off));
   ze.setTime(time);
   off += 4;
   ze.setCrc(ZipLong.getValue(this.CFH_BUF, off));
   off += 4;
   ze.setCompressedSize(ZipLong.getValue(this.CFH_BUF, off));
   off += 4;
   ze.setSize(ZipLong.getValue(this.CFH_BUF, off));
   off += 4;
   final int fileNameLen = ZipShort.getValue(this.CFH_BUF, off);
   off += 2;
   final int extraLen = ZipShort.getValue(this.CFH_BUF, off);
   off += 2;
   final int commentLen = ZipShort.getValue(this.CFH_BUF, off);
   off += 2;
   final int diskStart = ZipShort.getValue(this.CFH_BUF, off);
   off += 2;
   ze.setInternalAttributes(ZipShort.getValue(this.CFH_BUF, off));
   off += 2;
   ze.setExternalAttributes(ZipLong.getValue(this.CFH_BUF, off));
   off += 4;
   final byte[] fileName = new byte[fileNameLen];
   this.archive.readFully(fileName);
   ze.setName(entryEncoding.decode(fileName), fileName);
   offset.headerOffset = ZipLong.getValue(this.CFH_BUF, off);
   this.entries.add(ze);
   final byte[] cdExtraData = new byte[extraLen];
   this.archive.readFully(cdExtraData);
   ze.setCentralDirectoryExtra(cdExtraData);
   this.setSizesAndOffsetFromZip64Extra(ze, offset, diskStart);
   final byte[] comment = new byte[commentLen];
   this.archive.readFully(comment);
   ze.setComment(entryEncoding.decode(comment));
   if (!hasUTF8Flag && this.useUnicodeExtraFields) {
     noUTF8Flag.put(ze, new NameAndComment(fileName, comment));
   }
 }
Ejemplo n.º 3
0
 static {
   CFH_SIG = ZipLong.getValue(ZipOutputStream.CFH_SIG);
 }
Ejemplo n.º 4
0
 private void positionAtCentralDirectory32() throws IOException {
   this.skipBytes(16);
   this.archive.readFully(this.WORD_BUF);
   this.archive.seek(ZipLong.getValue(this.WORD_BUF));
 }