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); byte[] local = data[i].getCentralDirectoryData(); System.arraycopy(local, 0, result, start + WORD, local.length); start += (local.length + WORD); byte[] local = data[data.length - 1].getCentralDirectoryData(); 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); byte[] local = data[i].getLocalFileDataData(); System.arraycopy(local, 0, result, start + WORD, local.length); start += (local.length + WORD); byte[] local = data[data.length - 1].getLocalFileDataData(); System.arraycopy(local, 0, result, start, local.length);
existing = unparseableExtra; } else { existing = getExtraField(element.getHeaderId()); if (local || !(existing instanceof CentralDirectoryParsingZipExtraField)) { final byte[] b = element.getLocalFileDataData(); existing.parseFromLocalFileData(b, 0, b.length); } else { final byte[] b = element.getCentralDirectoryData(); ((CentralDirectoryParsingZipExtraField) existing) .parseFromCentralDirectoryData(b, 0, b.length);
ex[i] = ExtraFieldUtils .createExtraField(new ZipShort(extra[i] .getHeaderId() .getValue())); } catch (InstantiationException e) { throw new BuildException(e); byte[] b = extra[i].getCentralDirectoryData(); ex[i].parseFromCentralDirectoryData(b, 0, b.length); b = extra[i].getLocalFileDataData(); ex[i].parseFromLocalFileData(b, 0, b.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 * * @since 1.1 */ public static void register(Class<?> c) { try { ZipExtraField ze = (ZipExtraField) c.newInstance(); implementations.put(ze.getHeaderId(), c); } catch (ClassCastException cc) { throw new RuntimeException(c + " doesn\'t implement ZipExtraField"); //NOSONAR } catch (InstantiationException ie) { throw new RuntimeException(c + " is not a concrete class"); //NOSONAR } catch (IllegalAccessException ie) { throw new RuntimeException(c + "\'s no-arg constructor is not public"); //NOSONAR } }
ZipExtraField ze = createExtraField(headerId); if (local || !(ze instanceof CentralDirectoryParsingZipExtraField)) { ze.parseFromLocalFileData(data, start + WORD, length); } else { ((CentralDirectoryParsingZipExtraField) ze)
/** * Looks up an extra field by its header id. * * @param type ZipShort * @return null if no such field exists. */ public ZipExtraField getExtraField(final ZipShort type) { if (extraFields != null) { for (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 * @since 1.1 */ public void removeExtraField(final ZipShort type) { if (extraFields == null) { throw new NoSuchElementException(); } List<ZipExtraField> newResult = new ArrayList<>(); for (ZipExtraField extraField : extraFields) { if (!type.equals(extraField.getHeaderId())) { newResult.add(extraField); } } if (extraFields.length == newResult.size()) { throw new 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 * @since 1.1 */ public void addAsFirstExtraField(final 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(); }
/** * 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 * @since 1.1 */ 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[extraFields.length] = ze; extraFields = zipExtraFields; } } setExtra(); }