private void copyExistingFiles(ZipFile inputFile, ZipOutputStream outputFile) throws IOException { // First, copy the contents from the existing outFile: Enumeration<? extends ZipEntry> entries = inputFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = new ZipEntry(entries.nextElement()); // We can't reuse the compressed size because it depends on compression sizes. entry.setCompressedSize(-1); outputFile.putNextEntry(entry); // No need to create directory entries in the final apk if (! entry.isDirectory()) { BrutIO.copy(inputFile, outputFile, entry); } outputFile.closeEntry(); } }
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(); } }
@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(); }
ZipEntry entry = new ZipEntry(file.getName()); entry.setMethod(ZipEntry.STORED); entry.setCompressedSize(file.length()); entry.setSize(file.length()); entry.setCrc(crc.getValue());
crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
manifestCrc.update(manifest); entry.setSize(manifest.length); entry.setCompressedSize(-1); entry.setCrc(manifestCrc.getValue()); out.putNextEntry(entry);
crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
crc.update(bytes); outEntry.setCrc( crc.getValue() ); outEntry.setCompressedSize(bytes.length);
ze.setCompressedSize(ze.getSize()); } else if (ze.getSize() == -1) { ze.setSize(ze.getCompressedSize());
currentEntry.setCrc(ceCrc); currentEntry.setSize(ceSize); currentEntry.setCompressedSize(ceCompressedSize);
public void addMimeTypeFile(String statedPath, String actualPath) throws IOException { // byte data[] = new byte[BUFFER]; CRC32 crc = new CRC32(); // FileInputStream fi = new FileInputStream(actualPath); // BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); out.setLevel(0); ZipEntry entry = new ZipEntry(statedPath); entry.setExtra(null); names.add(statedPath); String contents = "application/epub+zip"; crc.update(contents.getBytes()); entry.setCompressedSize(contents.length()); entry.setSize(contents.length()); entry.setCrc(crc.getValue()); entry.setMethod(ZipEntry.STORED); out.putNextEntry(entry); // int count; // while ((count = origin.read(data, 0, BUFFER)) != -1) { // out.write(data, 0, count); // } // origin.close(); out.write(contents.getBytes(),0,contents.length()); out.setLevel(Deflater.BEST_COMPRESSION); }
byte[] entryData = ByteStreams.toByteArray(is); zipEntry.setSize(entryData.length); zipEntry.setCompressedSize(entryData.length); zipEntry.setCrc(computeCrc32(entryData)); outZip.putNextEntry(zipEntry);
private static ZipEntry getAsicMimeTypeZipEntry(byte[] mimeTypeBytes) { ZipEntry entryMimetype = new ZipEntry(ZIP_ENTRY_MIMETYPE); entryMimetype.setMethod(ZipEntry.STORED); entryMimetype.setSize(mimeTypeBytes.length); entryMimetype.setCompressedSize(mimeTypeBytes.length); CRC32 crc = new CRC32(); crc.update(mimeTypeBytes); entryMimetype.setCrc(crc.getValue()); return entryMimetype; }
private ZipEntry getZipEntryMimeType(final byte[] mimeTypeBytes) { final ZipEntry entryMimetype = new ZipEntry(ZIP_ENTRY_MIMETYPE); entryMimetype.setMethod(ZipEntry.STORED); entryMimetype.setSize(mimeTypeBytes.length); entryMimetype.setCompressedSize(mimeTypeBytes.length); final CRC32 crc = new CRC32(); crc.update(mimeTypeBytes); entryMimetype.setCrc(crc.getValue()); return entryMimetype; }
public void setCompressedSize(@Nonnull Bytes size) { getHandle().setCompressedSize(size.getB()); }
private void writeMimeType(ZipOutputStream zip) throws IOException { byte[] content = "application/epub+zip".getBytes("UTF-8"); ZipEntry entry = new ZipEntry("mimetype"); entry.setMethod(ZipEntry.STORED); entry.setSize(20); entry.setCompressedSize(20); entry.setCrc(0x2CAB616F); // pre-computed zip.putNextEntry(entry); zip.write(content); zip.closeEntry(); }
public void setCompressedSize(@Nonnull Bytes size) { getHandle().setCompressedSize(size.getB()); }
public void updateFile(Path outputPath, List<T.V3<String, byte[], ZipEntry>> files) { try (ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(outputPath.toFile()))) { for (V3<String, byte[], ZipEntry> v : files) { ZipEntry zipEntry = (ZipEntry)v.getC().clone(); zipEntry.setCompressedSize(-1); zipEntry.setSize(v.getB().length); zipFile.putNextEntry(zipEntry); zipFile.write(v.getB()); } } catch (IOException e) { throw new RuntimeException("Cannot store zip file ("+outputPath+")" + e.getMessage(), e); } } public static Comparator<? super V2<String, byte[]>> fileListComparator() {
/** Returns an output stream for writing the ZIP entry contents. */ @Override public OutputStream output() throws IOException { if (directory()) { entry.setMethod(ZipOutputStream.STORED); entry.setSize(0); entry.setCompressedSize(0); entry.setCrc(0); } return output.stream(entry); } }