示例#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 (int i = 0; i < f.length; i++) {
       ZipExtraField existing;
       if (f[i] instanceof UnparseableExtraFieldData) {
         existing = unparseableExtra;
       } else {
         existing = getExtraField(f[i].getHeaderId());
       }
       if (existing == null) {
         addExtraField(f[i]);
       } else {
         if (local || !(existing instanceof CentralDirectoryParsingZipExtraField)) {
           byte[] b = f[i].getLocalFileDataData();
           existing.parseFromLocalFileData(b, 0, b.length);
         } else {
           byte[] b = f[i].getCentralDirectoryData();
           ((CentralDirectoryParsingZipExtraField) existing)
               .parseFromCentralDirectoryData(b, 0, b.length);
         }
       }
     }
     setExtra();
   }
 }
示例#2
0
 /** Removes unparseable extra field data. */
 public void removeUnparseableExtraFieldData() {
   if (unparseableExtra == null) {
     throw new java.util.NoSuchElementException();
   }
   unparseableExtra = null;
   setExtra();
 }
示例#3
0
 /**
  * Remove an extra field.
  *
  * @param type the type of extra field to remove
  * @since 1.1
  */
 public void removeExtraField(ZipShort type) {
   if (extraFields == null) {
     throw new java.util.NoSuchElementException();
   }
   if (extraFields.remove(type) == null) {
     throw new java.util.NoSuchElementException();
   }
   setExtra();
 }
示例#4
0
 /**
  * Creates a new zip entry with fields taken from the specified zip entry.
  *
  * @param entry the entry to get fields from
  * @since 1.1
  * @throws ZipException on error
  */
 public ZipEntry(java.util.zip.ZipEntry entry) throws ZipException {
   super(entry);
   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();
   }
 }
示例#5
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
  * @since 1.1
  */
 public void addExtraField(ZipExtraField ze) {
   if (ze instanceof UnparseableExtraFieldData) {
     unparseableExtra = (UnparseableExtraFieldData) ze;
   } else {
     if (extraFields == null) {
       extraFields = new LinkedHashMap();
     }
     extraFields.put(ze.getHeaderId(), ze);
   }
   setExtra();
 }
示例#6
0
 /**
  * Replaces all currently attached extra fields with the new array.
  *
  * @param fields an array of extra fields
  * @since 1.1
  */
 public void setExtraFields(ZipExtraField[] fields) {
   extraFields = new LinkedHashMap();
   for (int i = 0; i < fields.length; i++) {
     if (fields[i] instanceof UnparseableExtraFieldData) {
       unparseableExtra = (UnparseableExtraFieldData) fields[i];
     } else {
       extraFields.put(fields[i].getHeaderId(), fields[i]);
     }
   }
   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
  * @since 1.1
  */
 public void addAsFirstExtraField(ZipExtraField ze) {
   if (ze instanceof UnparseableExtraFieldData) {
     unparseableExtra = (UnparseableExtraFieldData) ze;
   } else {
     LinkedHashMap copy = extraFields;
     extraFields = new LinkedHashMap();
     extraFields.put(ze.getHeaderId(), ze);
     if (copy != null) {
       copy.remove(ze.getHeaderId());
       extraFields.putAll(copy);
     }
   }
   setExtra();
 }