Ejemplo n.º 1
0
 /**
  * Creates a new zip entry with fields taken from the specified zip entry.
  *
  * <p>Assumes the entry represents a directory if and only if the name ends with a forward slash
  * "/".
  *
  * @param entry the entry to get fields from
  * @throws ZipException on error
  */
 public ZipArchiveEntry(ZipArchiveEntry entry) throws ZipException {
   this((java.util.zip.ZipEntry) entry);
   setInternalAttributes(entry.getInternalAttributes());
   setExternalAttributes(entry.getExternalAttributes());
   setExtraFields(getAllExtraFieldsNoCopy());
   setPlatform(entry.getPlatform());
   GeneralPurposeBit other = entry.getGeneralPurposeBit();
   setGeneralPurposeBit(other == null ? null : (GeneralPurposeBit) other.clone());
 }
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));
   }
 }
  private void writeVersionNeededToExtractAndGeneralPurposeBits(
      final int zipMethod, final boolean utfFallback, final boolean zip64) throws IOException {

    // CheckStyle:MagicNumber OFF
    int versionNeededToExtract = INITIAL_VERSION;
    GeneralPurposeBit b = new GeneralPurposeBit();
    b.useUTF8ForNames(useUTF8Flag || utfFallback);
    if (zipMethod == DEFLATED && raf == null) {
      // requires version 2 as we are going to store length info
      // in the data descriptor
      versionNeededToExtract = DATA_DESCRIPTOR_MIN_VERSION;
      b.useDataDescriptor(true);
    }
    if (zip64) {
      versionNeededToExtract = ZIP64_MIN_VERSION;
    }
    // CheckStyle:MagicNumber ON

    // version needed to extract
    writeOut(ZipShort.getBytes(versionNeededToExtract));
    // general purpose bit flag
    writeOut(b.encode());
  }
Ejemplo n.º 4
0
 /* (non-Javadoc)
  * @see java.lang.Object#equals(java.lang.Object)
  */
 @Override
 public boolean equals(Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj == null || getClass() != obj.getClass()) {
     return false;
   }
   ZipArchiveEntry other = (ZipArchiveEntry) obj;
   String myName = getName();
   String otherName = other.getName();
   if (myName == null) {
     if (otherName != null) {
       return false;
     }
   } else if (!myName.equals(otherName)) {
     return false;
   }
   String myComment = getComment();
   String otherComment = other.getComment();
   if (myComment == null) {
     myComment = "";
   }
   if (otherComment == null) {
     otherComment = "";
   }
   return getTime() == other.getTime()
       && myComment.equals(otherComment)
       && getInternalAttributes() == other.getInternalAttributes()
       && getPlatform() == other.getPlatform()
       && getExternalAttributes() == other.getExternalAttributes()
       && getMethod() == other.getMethod()
       && getSize() == other.getSize()
       && getCrc() == other.getCrc()
       && getCompressedSize() == other.getCompressedSize()
       && Arrays.equals(getCentralDirectoryExtra(), other.getCentralDirectoryExtra())
       && Arrays.equals(getLocalFileDataExtra(), other.getLocalFileDataExtra())
       && gpb.equals(other.gpb);
 }