public static void addFolderToZip(ZipOutputStream zos, String path, String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } // add folder record if (!StringUtil.endsWithChar(path, '/')) { path += '/'; } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zipEntry.setSize(0); zipEntry.setCrc(0); zos.putNextEntry(zipEntry); zos.closeEntry(); }
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(file)); CRC32 crc = BrutIO.calculateCrc(unknownFile); zipEntry.setCrc(crc.getValue()); unknownFile.close(); } else {
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files) throws BrutException, IOException { File unknownFileDir = new File(appDir, UNK_DIRNAME); // loop through unknown files for (Map.Entry<String,String> unknownFileInfo : files.entrySet()) { File inputFile = new File(unknownFileDir, BrutIO.sanitizeUnknownFile(unknownFileDir, unknownFileInfo.getKey())); if (inputFile.isDirectory()) { continue; } ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey()); int method = Integer.parseInt(unknownFileInfo.getValue()); LOGGER.fine(String.format("Copying unknown file %s with method %d", unknownFileInfo.getKey(), method)); if (method == ZipEntry.STORED) { newEntry.setMethod(ZipEntry.STORED); newEntry.setSize(inputFile.length()); newEntry.setCompressedSize(-1); BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile)); CRC32 crc = BrutIO.calculateCrc(unknownFile); newEntry.setCrc(crc.getValue()); } else { newEntry.setMethod(ZipEntry.DEFLATED); } outputFile.putNextEntry(newEntry); BrutIO.copy(inputFile, outputFile); outputFile.closeEntry(); } }
public static void addFolderToZip(final ZipOutputStream zos, String path, final String comment) throws IOException { while (path.length() != 0 && path.charAt(0) == '/') { path = path.substring(1); } // add folder record if (!StringUtil.endsWithChar(path, '/')) { path += '/'; } ZipEntry zipEntry = new ZipEntry(path); zipEntry.setTime(System.currentTimeMillis()); if (comment != null) { zipEntry.setComment(comment); } zipEntry.setSize(0); zipEntry.setCrc(0); zos.putNextEntry(zipEntry); zos.closeEntry(); }
@Override public void closeEntry() throws IOException { ZipEntry delayedEntry = this.delayedEntry; if (delayedEntry != null) { AccessBufByteArrayOutputStream delayedOutputStream = this.delayedOutputStream; byte[] buf = delayedOutputStream.getBuf(); int size = delayedOutputStream.size(); delayedEntry.setSize(size); delayedEntry.setCompressedSize(size); crc.reset(); crc.update(buf, 0, size); delayedEntry.setCrc(crc.getValue()); super.putNextEntry(delayedEntry); super.write(buf, 0, size); this.delayedEntry = null; delayedOutputStream.reset(); } super.closeEntry(); }
private void addFile(ZipOutputStream output, File file, String prefix, boolean compress) throws IOException { //Make sure file exists if (!file.exists()) { return; } ZipEntry entry = new ZipEntry(getEntryName(file, prefix)); entry.setTime(file.lastModified()); entry.setSize(file.length()); if (!compress) { entry.setCrc(calcChecksum(file)); } addToOutputStream(output, Files.newInputStream(file.toPath()), entry); }
entry.setCompressedSize(file.length()); entry.setSize(file.length()); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) {
CRC32 crc = new CRC32(); crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
zipEntry.setCrc(0);
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(); } }
public ZipEntry getEntry() { ZipEntry entry = new ZipEntry(path); if (bytes != null) { entry.setSize(bytes.length); } if(compressionMethod != -1) { entry.setMethod(compressionMethod); } if(crc != -1L) { entry.setCrc(crc); } entry.setTime(time); return entry; }
CRC32 crc = new CRC32(); crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
CRC32 crc = new CRC32(); crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
zipEntry.setCrc(0);
CRC32 crc = new CRC32(); crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
outputEntry.setCrc(inputEntry.getCrc()); outputEntry.setSize(inputEntry.getSize());
/** * 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; }
currentEntry.setMethod(ceCompressionMethod); if (ceSize != -1) { currentEntry.setCrc(ceCrc); currentEntry.setSize(ceSize); currentEntry.setCompressedSize(ceCompressedSize);
private static void zipStoreBuffer(ZipArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException { ZipEntry zipEntry = new ZipEntry(name != null ? name : UUID.randomUUID().toString()); zipEntry.setMethod(ZipOutputStream.STORED); zipEntry.setSize(dataBuffer.length); CRC32 crc32 = new CRC32(); crc32.update(dataBuffer); zipEntry.setCrc(crc32.getValue()); try { zip.putArchiveEntry(new ZipArchiveEntry(zipEntry)); } catch (ZipException ex) { if (name != null) { zipStoreBuffer(zip, "x-" + name, dataBuffer); return; } } zip.write(dataBuffer); zip.closeArchiveEntry(); }