long guessOffsetFor(ZipFile zipFile, ZipEntry zipEntry) { Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); long offset = 0; while (zipEntries.hasMoreElements()) { ZipEntry entry = zipEntries.nextElement(); long fileSize = 0; long extra = entry.getExtra() == null ? 0 : entry.getExtra().length; offset += 30 + entry.getName().length() + extra; if (entry.getName().equals(zipEntry.getName())) { return offset; } if(!entry.isDirectory()) { fileSize = entry.getCompressedSize(); // Do stuff here with fileSize & offset } offset += fileSize; } throw new IllegalStateException("'" + zipEntry.getName() + "' not found"); } /*
public ZipEntry newZipEntry(ZipEntry ze) { ZipEntry ze2 = new ZipEntry(ze.getName()); ze2.setComment(ze.getComment()); ze2.setTime(ze.getTime()); ze2.setExtra(ze.getExtra()); return ze2; }
/** * Copy entry with another name. * * @param original - zipEntry to copy * @param newName - new entry name, optional, if null, ogirinal's entry * @return copy of the original entry, but with the given name */ static ZipEntry copy(ZipEntry original, String newName) { ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName); if (original.getCrc() != -1) { copy.setCrc(original.getCrc()); } if (original.getMethod() != -1) { copy.setMethod(original.getMethod()); } if (original.getSize() >= 0) { copy.setSize(original.getSize()); } if (original.getExtra() != null) { copy.setExtra(original.getExtra()); } copy.setComment(original.getComment()); copy.setTime(original.getTime()); return copy; }
outputEntry.setExtra(inputEntry.getExtra()); outputEntry.setComment(inputEntry.getComment()); outputEntry.setTime(inputEntry.getTime());
/** * 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 "/".</p> * * @param entry the entry to get fields from * @since 1.1 * @throws ZipException on error */ public ZipEntry(final java.util.zip.ZipEntry entry) throws ZipException { super(entry); setName(entry.getName()); final 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(); }
/** * 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 "/".</p> * * @param entry the entry to get fields from * @throws ZipException on error */ public ZipArchiveEntry(final java.util.zip.ZipEntry entry) throws ZipException { super(entry); setName(entry.getName()); final 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(); }
/** * 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 "/".</p> * * @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); 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(); }
/** * Add file permissions info to ZIP entry. * Current implementation adds "ASi Unix" (tag 0x756e) extra block to entry. * * @param zipEntry ZIP entry * @param permissions permissions to assign */ static boolean setZTFilePermissions(ZipEntry zipEntry, ZTFilePermissions permissions) { try { List<ZipExtraField> fields = ExtraFieldUtils.parse(zipEntry.getExtra()); AsiExtraField asiExtraField = getFirstAsiExtraField(fields); if (asiExtraField == null) { asiExtraField = new AsiExtraField(); fields.add(asiExtraField); } asiExtraField.setDirectory(zipEntry.isDirectory()); asiExtraField.setMode(ZTFilePermissionsUtil.toPosixFileMode(permissions)); zipEntry.setExtra(ExtraFieldUtils.mergeLocalFileDataData(fields)); return true; } catch (java.util.zip.ZipException ze) { return false; } }
/** * Get assigned to ZIP entry file permissions info. Current implementation tries to read "ASi Unix" (tag 0x756e) extra tag. * "ASi Unix" * * @param zipEntry * @return file permissions info or <code>null</code> if ZIP entry does not have "ASi Unix" extra field. */ static ZTFilePermissions getZTFilePermissions(ZipEntry zipEntry) { try { ZTFilePermissions permissions = null; List<ZipExtraField> fields = ExtraFieldUtils.parse(zipEntry.getExtra()); AsiExtraField asiExtraField = getFirstAsiExtraField(fields); if (asiExtraField != null) { int mode = asiExtraField.getMode() & 0777; permissions = ZTFilePermissionsUtil.fromPosixFileMode(mode); } return permissions; } catch (java.util.zip.ZipException ze) { throw new ZipException(ze); } }
@Override public synchronized InputStream getInputStream(ZipEntry ze) throws IOException { return new ByteArrayInputStream(ze.getExtra()); } }
ZipResource(ZipFile zip, ZipEntry entry, long lastModified) throws UnsupportedEncodingException { this.zip = zip; this.entry = entry; this.lastModified = lastModified; byte[] data = entry.getExtra(); if (data != null) this.extra = new String(data, "UTF-8"); }
ZipResource(ZipFile zip, ZipEntry entry) throws UnsupportedEncodingException { this.zip = zip; this.entry = entry; this.lastModified = -11L; byte[] data = entry.getExtra(); if (data != null) this.extra = new String(data, "UTF-8"); }
private ZipResource(ZipFile zip, ZipEntry entry, boolean closeZipFile) { this.zip = zip; this.entry = entry; this.closeZipFile = closeZipFile; lastModified = -11L; size = entry.getSize(); byte[] data = entry.getExtra(); if (data != null) { extra = new String(data, UTF_8); } }
private ZipResource(ZipFile zip, ZipEntry entry, boolean closeZipFile) { this.zip = zip; this.entry = entry; this.closeZipFile = closeZipFile; lastModified = -11L; size = entry.getSize(); byte[] data = entry.getExtra(); if (data != null) { extra = new String(data, UTF_8); } }
protected void writeExtraBytes(ZipEntry entry) throws IOException { byte[] extraBytes = entry.getExtra(); if (extraBytes != null) { writeBytes(extraBytes); } }
private static int getFilesCount(ZipEntry entry) throws IOException { byte[] bytes = entry.getExtra(); if (bytes == null) { return 0; } else if (bytes.length != 4) { throw new IOException("Invalid Nuxeo Archive"); } else { return new DWord(bytes).getInt(); } }
@Override public Payload.Part next() { final Extra extra = new Extra(nextEntry.getExtra()); final Payload.Part part = new ZipPayloadImpl.Part( nextEntry.getName(), extra.getContentType(), extra.getProperties(), Inbound.this); isNextEntryPrefetched = false; return part; }
public ZipEntry newZipEntry(ZipEntry ze) { ZipEntry ze2 = new ZipEntry(ze.getName()); ze2.setComment(ze.getComment()); ze2.setTime(ze.getTime()); ze2.setExtra(ze.getExtra()); return ze2; }
private void validateMimeTypeEntry(ZipEntry mimetypeEntry, String firstEntryName) { if (mimetypeEntry.getMethod() != ZipEntry.STORED) { logValidationError(OdfPackageConstraint.MIMETYPE_IS_COMPRESSED, getBaseURI()); } if (mimetypeEntry.getExtra() != null) { logValidationError(OdfPackageConstraint.MIMETYPE_HAS_EXTRA_FIELD, getBaseURI()); } if (!OdfFile.MEDIA_TYPE.getPath().equals(firstEntryName)) { logValidationError(OdfPackageConstraint.MIMETYPE_NOT_FIRST_IN_PACKAGE, getBaseURI()); } }
private void validateMimeTypeEntry(ZipEntry mimetypeEntry, String firstEntryName) throws SAXException { if (mimetypeEntry.getMethod() != ZipEntry.STORED) { logValidationError(OdfPackageConstraint.MIMETYPE_IS_COMPRESSED, getBaseURI()); } if (mimetypeEntry.getExtra() != null) { logValidationError(OdfPackageConstraint.MIMETYPE_HAS_EXTRA_FIELD, getBaseURI()); } if (!OdfFile.MEDIA_TYPE.getPath().equals(firstEntryName)) { logValidationError(OdfPackageConstraint.MIMETYPE_NOT_FIRST_IN_PACKAGE, getBaseURI()); } }