@Override public int getCompressionLevel(String fileName) throws DirectoryException { ZipEntry entry = getZipFileEntry(fileName); return entry.getMethod(); }
@Override public void putNextEntry(ZipEntry e) throws IOException { if (e.getMethod() != ZipEntry.STORED) { super.putNextEntry(e); } else { delayedEntry = e; if (delayedOutputStream == null) { delayedOutputStream = new AccessBufByteArrayOutputStream(); } } }
private void getCompressMethodFromApk() { ZipFile zipFile = null; try { zipFile = new ZipFile(config.mNewApkFile); ArrayList<String> sets = new ArrayList<>(); sets.addAll(modifiedSet); sets.addAll(addedSet); ZipEntry zipEntry; for (String name : sets) { zipEntry = zipFile.getEntry(name); if (zipEntry != null && zipEntry.getMethod() == ZipEntry.STORED) { storedSet.add(name); } } } catch (Throwable throwable) { } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }
/** * Writes data for the current entry to the underlying stream. * * @exception IOException * If an error occurs writing to the stream */ @Override public void write(byte[] buffer, int offset, int byteCount) throws IOException { Arrays.checkOffsetAndCount(buffer.length, offset, byteCount); if (currentEntry == null) { throw new ZipException("No active entry"); } if (currentEntry.getMethod() == STORED) { out.write(buffer, offset, byteCount); } else { super.write(buffer, offset, byteCount); } crc.update(buffer, offset, byteCount); }
private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException { Enumeration<? extends ZipEntry> sourceEntries = source.entries(); while (sourceEntries.hasMoreElements()) { ZipEntry sourceEntry = sourceEntries.nextElement(); String sourceEntryName = sourceEntry.getName(); if (sourceEntryName.endsWith(".dex") || isSignatureFile(sourceEntryName)) { continue; } // separate ZipEntry avoids compression problems due to encodings ZipEntry destinationEntry = new ZipEntry(sourceEntryName); // use the same compression method as the original (certain files // are stored, not compressed) destinationEntry.setMethod(sourceEntry.getMethod()); // copy other necessary fields for STORE method destinationEntry.setSize(sourceEntry.getSize()); destinationEntry.setCrc(sourceEntry.getCrc()); // finally craft new entry destination.putNextEntry(destinationEntry); InputStream zipEntryInput = source.getInputStream(sourceEntry); byte[] buffer = new byte[2048]; int bytesRead = zipEntryInput.read(buffer); while (bytesRead > 0) { destination.write(buffer, 0, bytesRead); bytesRead = zipEntryInput.read(buffer); } zipEntryInput.close(); } }
/** * Returns the compression method of a given entry of the ZIP file. * * @param zip * ZIP file. * @param name * entry name. * @return Returns <code>ZipEntry.STORED</code>, <code>ZipEntry.DEFLATED</code> or -1 if * the ZIP file does not contain the given entry. */ public static int getCompressionMethodOfEntry(File zip, String name) { ZipFile zf = null; try { zf = new ZipFile(zip); ZipEntry zipEntry = zf.getEntry(name); if (zipEntry == null) { return -1; } return zipEntry.getMethod(); } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } finally { closeQuietly(zf); } }
FileMap createEntryFileMap(ZipEntryRO entry) { // final _ZipEntryRO *zipEntry = reinterpret_cast<_ZipEntryRO*>(entry); // const ZipEntry& ze = zipEntry->entry; ZipEntry ze = entry.entry; // int fd = GetFileDescriptor(mHandle); int fd = -1; int actualLen = 0; if (ze.getMethod() == kCompressStored) { actualLen = toIntExact(ze.getSize()); } else { actualLen = toIntExact(ze.getCompressedSize()); } FileMap newMap = new FileMap(); if (!newMap.createFromZip(mFileName, mHandle.zipFile, entry.entry, actualLen, true)) { // delete newMap; return null; } return newMap; }
boolean getEntryInfo(org.robolectric.res.android.ZipFileRO.ZipEntryRO entry, Ref<Short> pMethod, final Ref<Long> pUncompLen, Ref<Long> pCompLen, Ref<Long> pOffset, final Ref<Long> pModWhen, Ref<Long> pCrc32) { final ZipEntryRO zipEntry = /*reinterpret_cast<ZipEntryRO*>*/(entry); final ZipEntry ze = zipEntry.entry; if (pMethod != null) { pMethod.set((short) ze.getMethod()); } if (pUncompLen != null) { pUncompLen.set(ze.getSize()); // uncompressed_length } if (pCompLen != null) { pCompLen.set(ze.getCompressedSize()); } if (pOffset != null) { throw new UnsupportedOperationException("Figure out offset"); // pOffset = ze.offset; } if (pModWhen != null) { // todo pModWhen.set(ze.getLastModifiedTime().toMillis()); } if (pCrc32 != null) { pCrc32.set(ze.getCrc()); } return true; }
if (entry.entry.getMethod() == kCompressDeflated) {
/** * 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; }
/** * 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(); }
if (entry.get().getMethod() == kCompressDeflated) { System.out.println(kResourcesArsc + " in APK '" + path + "' is compressed.");
private static ArrayMemory zipEntryToArray(ZipEntry zipEntry) { final ArrayMemory result = new ArrayMemory(); result.refOfIndex("name").assign(zipEntry.getName()); result.refOfIndex("crc").assign(zipEntry.getCrc()); result.refOfIndex("size").assign(zipEntry.getSize()); result.refOfIndex("compressedSize").assign(zipEntry.getCompressedSize()); result.refOfIndex("time").assign(zipEntry.getTime()); result.refOfIndex("method").assign(zipEntry.getMethod()); result.refOfIndex("comment").assign(zipEntry.getComment()); result.refOfIndex("directory").assign(zipEntry.isDirectory()); return result; }
return; if (currentEntry.getMethod() == DEFLATED) { super.finish(); if (currentEntry.getMethod() == STORED) { if (crc.getValue() != currentEntry.crc) { throw new ZipException("CRC mismatch"); if (currentEntry.getMethod() != STORED) { curOffset += EXTHDR; writeLong(out, EXTSIG); int flags = currentEntry.getMethod() == STORED ? 0 : ZipFile.GPBF_DATA_DESCRIPTOR_FLAG; writeShort(cDir, currentEntry.getMethod()); writeShort(cDir, currentEntry.time); writeShort(cDir, currentEntry.modDate); writeLong(cDir, crc.getValue()); if (currentEntry.getMethod() == DEFLATED) { curOffset += writeLong(cDir, def.getTotalOut()); writeLong(cDir, def.getTotalIn());