List of usage examples for java.util.zip ZipEntry STORED
int STORED
To view the source code for java.util.zip ZipEntry STORED.
Click Source Link
From source file:org.jboss.tools.windup.ui.internal.archiver.ZipFileExporter.java
/** * @see org.jboss.tools.windup.ui.internal.archiver.AbstractArchiveFileExporter#createOutputStream(java.lang.String, boolean) *//*from ww w.j av a2 s .c om*/ @Override protected ArchiveOutputStream createOutputStream(String archiveName, boolean compress) throws IOException { ZipArchiveOutputStream zipOut = new ZipArchiveOutputStream(new FileOutputStream(archiveName)); zipOut.setMethod(compress ? ZipEntry.DEFLATED : ZipEntry.STORED); return zipOut; }
From source file:org.kuali.kfs.module.ar.document.service.impl.DunningLetterServiceImpl.java
/** * This method generates the actual pdf files to print. * * @param mapping/*from w w w . j a va 2 s . c o m*/ * @param form * @param list * @return */ @Override public boolean createZipOfPDFs(byte[] report, ByteArrayOutputStream baos) throws IOException { ZipOutputStream zos = new ZipOutputStream(baos); int bytesRead; byte[] buffer = new byte[1024]; CRC32 crc = new CRC32(); if (ObjectUtils.isNotNull(report)) { BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(report)); crc.reset(); while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); } bis.close(); // Reset to beginning of input stream bis = new BufferedInputStream(new ByteArrayInputStream(report)); ZipEntry entry = new ZipEntry("DunningLetters&Invoices-" + getDateTimeService().toDateStringForFilename(getDateTimeService().getCurrentDate()) + ".pdf"); entry.setMethod(ZipEntry.STORED); entry.setCompressedSize(report.length); entry.setSize(report.length); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) { zos.write(buffer, 0, bytesRead); } bis.close(); } zos.close(); return true; }
From source file:org.kuali.kfs.module.ar.report.service.impl.TransmitContractsAndGrantsInvoicesServiceImpl.java
/** * * @param report// w w w . j av a 2 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 mkOOoZip(File directory, File outFile) throws IOException { try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(outFile))) { File manif = new File(directory, "mimetype"); writeOOoEntry(zipOutputStream, manif.getName(), manif, ZipEntry.STORED); for (File fileEntry : directory.listFiles()) { if (!fileEntry.getName().equals(manif.getName())) { writeOOoEntry(zipOutputStream, fileEntry.getName(), fileEntry, ZipEntry.DEFLATED); }/*from ww w . ja v a 2 s.c o m*/ } } }
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 w w w . j a va 2 s .co 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(); }
From source file:org.springframework.boot.loader.tools.JarWriter.java
private void setUpEntry(JarFile jarFile, JarArchiveEntry entry) throws IOException { try (ZipHeaderPeekInputStream inputStream = new ZipHeaderPeekInputStream(jarFile.getInputStream(entry))) { if (inputStream.hasZipHeader() && entry.getMethod() != ZipEntry.STORED) { new CrcAndSize(inputStream).setupStoredEntry(entry); } else {/*from w ww. j av a 2 s.co m*/ entry.setCompressedSize(-1); } } }
From source file:org.springframework.boot.loader.tools.RepackagerTests.java
@Test public void dontRecompressZips() throws Exception { TestJarFile nested = new TestJarFile(this.temporaryFolder); nested.addClass("a/b/C.class", ClassWithoutMainMethod.class); File nestedFile = nested.getFile(); this.testJarFile.addFile("test/nested.jar", nestedFile); this.testJarFile.addClass("A.class", ClassWithMainMethod.class); File file = this.testJarFile.getFile(); Repackager repackager = new Repackager(file); repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE))); try (JarFile jarFile = new JarFile(file)) { assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()) .isEqualTo(ZipEntry.STORED); assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED); }// ww w. j av a 2 s. c o m }
From source file:VASSAL.tools.io.ZipArchive.java
/** * Gets an {@link OutputStream} to write to the given file. * * <b>Note:</b> It is imperative the that calling code ensures that this * stream is eventually closed, since the returned stream holds a write * lock on the archive.// w ww.j a va 2 s.c om * * @param path the path to the file in the archive * @param compress whether to compress the file * @return an <code>OutputStream</code> for the requested file * @throws IOException */ public OutputStream getOutputStream(String path, boolean compress) throws IOException { w.lock(); try { openIfClosed(); modified = true; // update the entries map Entry e = entries.get(path); if (e == null) { e = new Entry(null, null); entries.put(path, e); } // set up new ZipEntry final ZipEntry ze = new ZipEntry(path); ze.setMethod(compress ? ZipEntry.DEFLATED : ZipEntry.STORED); e.ze = ze; // clean up old temp file if (e.file != null) { e.file.delete(); } // create new temp file e.file = TempFileManager.getInstance().createTempFile("zip", ".tmp"); return new ZipArchiveOutputStream(new FileOutputStream(e.file), new CRC32(), e.ze); } catch (IOException ex) { w.unlock(); throw ex; } }