コード例 #1
0
 /**
  * Removes unparseable extra field data.
  *
  * @since 1.1
  */
 public void removeUnparseableExtraFieldData() {
   if (unparseableExtra == null) {
     throw new java.util.NoSuchElementException();
   }
   unparseableExtra = null;
   setExtra();
 }
コード例 #2
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();
   }
 }
コード例 #3
0
 /**
  * Replaces all currently attached extra fields with the new array.
  *
  * @param fields an array of extra fields
  */
 public void setExtraFields(ZipExtraField[] fields) {
   List<ZipExtraField> newFields = new ArrayList<ZipExtraField>();
   for (ZipExtraField field : fields) {
     if (field instanceof UnparseableExtraFieldData) {
       unparseableExtra = (UnparseableExtraFieldData) field;
     } else {
       newFields.add(field);
     }
   }
   extraFields = newFields.toArray(new ZipExtraField[newFields.size()]);
   setExtra();
 }
コード例 #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();
 }
コード例 #5
0
 /**
  * If the entry needs Zip64 extra information inside the central directory then configure its
  * data.
  */
 private void handleZip64Extra(ZipArchiveEntry ze, long lfhOffset, boolean needsZip64Extra) {
   if (needsZip64Extra) {
     Zip64ExtendedInformationExtraField z64 = getZip64Extra(ze);
     if (ze.getCompressedSize() >= ZIP64_MAGIC || ze.getSize() >= ZIP64_MAGIC) {
       z64.setCompressedSize(new ZipEightByteInteger(ze.getCompressedSize()));
       z64.setSize(new ZipEightByteInteger(ze.getSize()));
     } else {
       // reset value that may have been set for LFH
       z64.setCompressedSize(null);
       z64.setSize(null);
     }
     if (lfhOffset >= ZIP64_MAGIC) {
       z64.setRelativeHeaderOffset(new ZipEightByteInteger(lfhOffset));
     }
     ze.setExtra();
   }
 }
コード例 #6
0
  /**
   * Remove an extra field.
   *
   * @param type the type of extra field to remove
   */
  public void removeExtraField(ZipShort type) {
    if (extraFields == null) {
      throw new java.util.NoSuchElementException();
    }

    List<ZipExtraField> newResult = new ArrayList<ZipExtraField>();
    for (ZipExtraField extraField : extraFields) {
      if (!type.equals(extraField.getHeaderId())) {
        newResult.add(extraField);
      }
    }
    if (extraFields.length == newResult.size()) {
      throw new java.util.NoSuchElementException();
    }
    extraFields = newResult.toArray(new ZipExtraField[newResult.size()]);
    setExtra();
  }
コード例 #7
0
 /**
  * Adds an extra field - replacing an already present extra field of the same type.
  *
  * <p>The new extra field will be the first one.
  *
  * @param ze an extra field
  */
 public void addAsFirstExtraField(ZipExtraField ze) {
   if (ze instanceof UnparseableExtraFieldData) {
     unparseableExtra = (UnparseableExtraFieldData) ze;
   } else {
     if (getExtraField(ze.getHeaderId()) != null) {
       removeExtraField(ze.getHeaderId());
     }
     ZipExtraField[] copy = extraFields;
     int newLen = extraFields != null ? extraFields.length + 1 : 1;
     extraFields = new ZipExtraField[newLen];
     extraFields[0] = ze;
     if (copy != null) {
       System.arraycopy(copy, 0, extraFields, 1, extraFields.length - 1);
     }
   }
   setExtra();
 }
コード例 #8
0
 /**
  * Adds an extra field - replacing an already present extra field of the same type.
  *
  * <p>If no extra field of the same type exists, the field will be added as last field.
  *
  * @param ze an extra field
  */
 public void addExtraField(ZipExtraField ze) {
   if (ze instanceof UnparseableExtraFieldData) {
     unparseableExtra = (UnparseableExtraFieldData) ze;
   } else {
     if (extraFields == null) {
       extraFields = new ZipExtraField[] {ze};
     } else {
       if (getExtraField(ze.getHeaderId()) != null) {
         removeExtraField(ze.getHeaderId());
       }
       final ZipExtraField[] zipExtraFields = copyOf(extraFields, extraFields.length + 1);
       zipExtraFields[zipExtraFields.length - 1] = ze;
       extraFields = zipExtraFields;
     }
   }
   setExtra();
 }