List of usage examples for java.util.zip ZipEntry setCompressedSize
public void setCompressedSize(long csize)
From source file:org.kuali.kfs.module.ar.report.service.impl.TransmitContractsAndGrantsInvoicesServiceImpl.java
/** * * @param report//from w ww . j a va2 s. c o m * @param invoiceFileWritten * @param zos * @param buffer * @param crc * @return * @throws IOException */ private boolean writeFile(byte[] arrayToWrite, ZipOutputStream zos, String fileName) throws IOException { int bytesRead; byte[] buffer = new byte[1024]; CRC32 crc = new CRC32(); if (ObjectUtils.isNotNull(arrayToWrite) && arrayToWrite.length > 0) { BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(arrayToWrite)); try { while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); } bis.close(); // Reset to beginning of input stream bis = new BufferedInputStream(new ByteArrayInputStream(arrayToWrite)); ZipEntry entry = new ZipEntry(fileName); entry.setMethod(ZipEntry.STORED); entry.setCompressedSize(arrayToWrite.length); entry.setSize(arrayToWrite.length); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) { zos.write(buffer, 0, bytesRead); } } finally { bis.close(); } return true; } return false; }
From source file:org.nuxeo.template.odt.OOoArchiveModifier.java
protected void writeOOoEntry(ZipOutputStream zipOutputStream, String entryName, File fileEntry, int zipMethod) throws IOException { if (fileEntry.isDirectory()) { entryName = entryName + "/"; ZipEntry zentry = new ZipEntry(entryName); zipOutputStream.putNextEntry(zentry); zipOutputStream.closeEntry();//from ww w . j a v a 2s .c o m for (File child : fileEntry.listFiles()) { writeOOoEntry(zipOutputStream, entryName + child.getName(), child, zipMethod); } return; } ZipEntry zipEntry = new ZipEntry(entryName); try (InputStream entryInputStream = new FileInputStream(fileEntry)) { zipEntry.setMethod(zipMethod); if (zipMethod == ZipEntry.STORED) { byte[] inputBytes = IOUtils.toByteArray(entryInputStream); CRC32 crc = new CRC32(); crc.update(inputBytes); zipEntry.setCrc(crc.getValue()); zipEntry.setSize(inputBytes.length); zipEntry.setCompressedSize(inputBytes.length); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(inputBytes, zipOutputStream); } else { zipOutputStream.putNextEntry(zipEntry); IOUtils.copy(entryInputStream, zipOutputStream); } } zipOutputStream.closeEntry(); }