existing = unparseableExtra; } else { existing = getExtraField(element.getHeaderId()); } else { if (local) { final byte[] b = element.getLocalFileDataData(); existing.parseFromLocalFileData(b, 0, b.length); } else { final byte[] b = element.getCentralDirectoryData(); existing.parseFromCentralDirectoryData(b, 0, b.length);
sum += element.getCentralDirectoryLength().getValue(); System.arraycopy(data[i].getHeaderId().getBytes(), 0, result, start, 2); System.arraycopy(data[i].getCentralDirectoryLength().getBytes(), 0, result, start + 2, 2); start += WORD; final byte[] local = data[i].getCentralDirectoryData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length); final byte[] local = data[data.length - 1].getCentralDirectoryData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length);
sum += element.getLocalFileDataLength().getValue(); int start = 0; for (int i = 0; i < regularExtraFieldCount; i++) { System.arraycopy(data[i].getHeaderId().getBytes(), 0, result, start, 2); System.arraycopy(data[i].getLocalFileDataLength().getBytes(), 0, result, start + 2, 2); start += WORD; final byte[] local = data[i].getLocalFileDataData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length); final byte[] local = data[data.length - 1].getLocalFileDataData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length);
try { if (local) { ze.parseFromLocalFileData(data, start + WORD, length); } else { ze.parseFromCentralDirectoryData(data, start + WORD, length);
/** * Register a ZipExtraField implementation. * * <p>The given class must have a no-arg constructor and implement * the {@link ZipExtraField ZipExtraField interface}.</p> * @param c the class to register */ public static void register(final Class<?> c) { try { final ZipExtraField ze = (ZipExtraField) c.newInstance(); implementations.put(ze.getHeaderId(), c); } catch (final ClassCastException cc) { throw new RuntimeException(c + " doesn\'t implement ZipExtraField"); //NOSONAR } catch (final InstantiationException ie) { throw new RuntimeException(c + " is not a concrete class"); //NOSONAR } catch (final IllegalAccessException ie) { throw new RuntimeException(c + "\'s no-arg constructor is not public"); //NOSONAR } }
final ZipExtraField ze = createExtraField(headerId); if (local) { ze.parseFromLocalFileData(data, start + WORD, length); } else { ze.parseFromCentralDirectoryData(data, start + WORD, length);
/** * Looks up an extra field by its header id. * * @param type the header id * @return null if no such field exists. */ public ZipExtraField getExtraField(final ZipShort type) { if (extraFields != null) { for (final ZipExtraField extraField : extraFields) { if (type.equals(extraField.getHeaderId())) { return extraField; } } } return null; }
existing = unparseableExtra; } else { existing = getExtraField(element.getHeaderId()); } else { if (local) { final byte[] b = element.getLocalFileDataData(); existing.parseFromLocalFileData(b, 0, b.length); } else { final byte[] b = element.getCentralDirectoryData(); existing.parseFromCentralDirectoryData(b, 0, b.length);
ex[i].parseFromCentralDirectoryData(b, 0, b.length); b = extra[i].getLocalFileDataData(); ex[i].parseFromLocalFileData(b, 0, b.length);
/** * Remove an extra field. * @param type the type of extra field to remove */ public void removeExtraField(final ZipShort type) { if (extraFields == null) { throw new java.util.NoSuchElementException(); } final List<ZipExtraField> newResult = new ArrayList<>(); for (final 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(); }
sum += element.getCentralDirectoryLength().getValue(); System.arraycopy(data[i].getHeaderId().getBytes(), 0, result, start, 2); System.arraycopy(data[i].getCentralDirectoryLength().getBytes(), 0, result, start + 2, 2); start += WORD; final byte[] local = data[i].getCentralDirectoryData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length); final byte[] local = data[data.length - 1].getCentralDirectoryData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length);
sum += element.getLocalFileDataLength().getValue(); int start = 0; for (int i = 0; i < regularExtraFieldCount; i++) { System.arraycopy(data[i].getHeaderId().getBytes(), 0, result, start, 2); System.arraycopy(data[i].getLocalFileDataLength().getBytes(), 0, result, start + 2, 2); start += WORD; final byte[] local = data[i].getLocalFileDataData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length); final byte[] local = data[data.length - 1].getLocalFileDataData(); if (local != null) { System.arraycopy(local, 0, result, start, local.length);
/** * Adds an extra field - replacing an already present extra field * of the same type. * * <p>The new extra field will be the first one.</p> * @param ze an extra field */ public void addAsFirstExtraField(final ZipExtraField ze) { if (ze instanceof UnparseableExtraFieldData) { unparseableExtra = (UnparseableExtraFieldData) ze; } else { if (getExtraField(ze.getHeaderId()) != null){ removeExtraField(ze.getHeaderId()); } final ZipExtraField[] copy = extraFields; final 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(); }
/** * 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.</p> * @param ze an extra field */ public void addExtraField(final 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(); }
/** * Register a ZipExtraField implementation. * * <p>The given class must have a no-arg constructor and implement * the {@link ZipExtraField ZipExtraField interface}.</p> * @param c the class to register */ public static void register(final Class<?> c) { try { final ZipExtraField ze = (ZipExtraField) c.newInstance(); implementations.put(ze.getHeaderId(), c); } catch (final ClassCastException cc) { throw new RuntimeException(c + " doesn\'t implement ZipExtraField"); //NOSONAR } catch (final InstantiationException ie) { throw new RuntimeException(c + " is not a concrete class"); //NOSONAR } catch (final IllegalAccessException ie) { throw new RuntimeException(c + "\'s no-arg constructor is not public"); //NOSONAR } }
/** * Looks up an extra field by its header id. * * @param type the header id * @return null if no such field exists. */ public ZipExtraField getExtraField(final ZipShort type) { if (extraFields != null) { for (final ZipExtraField extraField : extraFields) { if (type.equals(extraField.getHeaderId())) { return extraField; } } } return null; }
/** * Remove an extra field. * @param type the type of extra field to remove */ public void removeExtraField(final ZipShort type) { if (extraFields == null) { throw new java.util.NoSuchElementException(); } final List<ZipExtraField> newResult = new ArrayList<>(); for (final 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(); }
/** * Adds an extra field - replacing an already present extra field * of the same type. * * <p>The new extra field will be the first one.</p> * @param ze an extra field */ public void addAsFirstExtraField(final ZipExtraField ze) { if (ze instanceof UnparseableExtraFieldData) { unparseableExtra = (UnparseableExtraFieldData) ze; } else { if (getExtraField(ze.getHeaderId()) != null){ removeExtraField(ze.getHeaderId()); } final ZipExtraField[] copy = extraFields; final 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(); }
/** * 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.</p> * @param ze an extra field */ public void addExtraField(final 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(); }
private ZipArchiveEntry filterZipEntry(ZipArchiveEntry entry) { // Set times entry.setCreationTime(FileTime.fromMillis(zipTimestamp)); entry.setLastAccessTime(FileTime.fromMillis(zipTimestamp)); entry.setLastModifiedTime(FileTime.fromMillis(zipTimestamp)); entry.setTime(zipTimestamp); // Remove extended timestamps for (ZipExtraField field : entry.getExtraFields()) { if (field instanceof X5455_ExtendedTimestamp) { entry.removeExtraField(field.getHeaderId()); } } return entry; } }