예제 #1
0
 /**
  * If there are no extra fields, use the given fields as new extra data - otherwise merge the
  * fields assuming the existing fields and the new fields stem from different locations inside the
  * archive.
  *
  * @param f the extra fields to merge
  * @param local whether the new fields originate from local data
  */
 private void mergeExtraFields(ZipExtraField[] f, boolean local) throws ZipException {
   if (extraFields == null) {
     setExtraFields(f);
   } else {
     for (ZipExtraField element : f) {
       ZipExtraField existing;
       if (element instanceof UnparseableExtraFieldData) {
         existing = unparseableExtra;
       } else {
         existing = getExtraField(element.getHeaderId());
       }
       if (existing == null) {
         addExtraField(element);
       } else {
         if (local) {
           byte[] b = element.getLocalFileDataData();
           existing.parseFromLocalFileData(b, 0, b.length);
         } else {
           byte[] b = element.getCentralDirectoryData();
           existing.parseFromCentralDirectoryData(b, 0, b.length);
         }
       }
     }
     setExtra();
   }
 }
예제 #2
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());
 }
예제 #3
0
  /**
   * Overwrite clone.
   *
   * @return a cloned copy of this ZipArchiveEntry
   */
  @Override
  public Object clone() {
    ZipArchiveEntry e = (ZipArchiveEntry) super.clone();

    e.setInternalAttributes(getInternalAttributes());
    e.setExternalAttributes(getExternalAttributes());
    e.setExtraFields(getAllExtraFieldsNoCopy());
    return e;
  }
예제 #4
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(java.util.zip.ZipEntry entry) throws ZipException {
   super(entry);
   setName(entry.getName());
   byte[] extra = entry.getExtra();
   if (extra != null) {
     setExtraFields(
         ExtraFieldUtils.parse(extra, true, ExtraFieldUtils.UnparseableExtraField.READ));
   } else {
     // initializes extra data to an empty byte array
     setExtra();
   }
   setMethod(entry.getMethod());
   this.size = entry.getSize();
 }