List of usage examples for java.util.zip ZipEntry DEFLATED
int DEFLATED
To view the source code for java.util.zip ZipEntry DEFLATED.
Click Source Link
From source file:brut.androlib.Androlib.java
private void copyUnknownFiles(File appDir, ZipOutputStream outputFile, Map<String, String> files) throws 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, unknownFileInfo.getKey()); if (inputFile.isDirectory()) { continue; }/* w ww . j ava2s .co m*/ ZipEntry newEntry = new ZipEntry(unknownFileInfo.getKey()); int method = Integer.valueOf(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(); } }
From source file:eu.europa.esig.dss.asic.signature.ASiCService.java
private void storeSignedFiles(final DSSDocument detachedDocument, final ZipOutputStream outZip) throws IOException { DSSDocument currentDetachedDocument = detachedDocument; do {/* ww w . j a v a 2 s . co m*/ final String detachedDocumentName = currentDetachedDocument.getName(); final String name = detachedDocumentName != null ? detachedDocumentName : ZIP_ENTRY_DETACHED_FILE; final ZipEntry entryDocument = new ZipEntry(name); outZip.setLevel(ZipEntry.DEFLATED); try { createZipEntry(outZip, entryDocument); final InputStream inputStream = currentDetachedDocument.openStream(); IOUtils.copy(inputStream, outZip); IOUtils.closeQuietly(inputStream); } catch (DSSException e) { if (!((e.getCause() instanceof ZipException) && e.getCause().getMessage().startsWith("duplicate entry:"))) { throw e; } } currentDetachedDocument = currentDetachedDocument.getNextDocument(); } while (currentDetachedDocument != null); }
From source file:org.apache.sling.reqanalyzer.impl.RequestAnalyzerWebConsole.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (req.getRequestURI().endsWith(RAW_FILE_MARKER) || req.getRequestURI().endsWith(ZIP_FILE_MARKER)) { InputStream input = null; OutputStream output = null; try {//from w w w . j a v a2 s. com input = new FileInputStream(this.logFile); output = resp.getOutputStream(); if (req.getRequestURI().endsWith(ZIP_FILE_MARKER)) { ZipOutputStream zip = new ZipOutputStream(output); zip.setLevel(Deflater.BEST_SPEED); ZipEntry entry = new ZipEntry(this.logFile.getName()); entry.setTime(this.logFile.lastModified()); entry.setMethod(ZipEntry.DEFLATED); zip.putNextEntry(entry); output = zip; resp.setContentType("application/zip"); } else { resp.setContentType("text/plain"); resp.setCharacterEncoding("UTF-8"); resp.setHeader("Content-Length", String.valueOf(this.logFile.length())); // might be bigger than } resp.setDateHeader("Last-Modified", this.logFile.lastModified()); IOUtils.copy(input, output); } catch (IOException ioe) { throw new ServletException("Cannot create copy of log file", ioe); } finally { IOUtils.closeQuietly(input); if (output instanceof ZipOutputStream) { ((ZipOutputStream) output).closeEntry(); ((ZipOutputStream) output).finish(); } } resp.flushBuffer(); } else if (req.getRequestURI().endsWith(WINDOW_MARKER)) { if (canOpenSwingGui(req)) { showWindow(); } String target = req.getRequestURI(); target = target.substring(0, target.length() - WINDOW_MARKER.length()); resp.sendRedirect(target); resp.flushBuffer(); } else { super.service(req, resp); } }
From source file:org.digidoc4j.impl.bdoc.asic.AsicContainerCreator.java
public void writeDataFiles(Collection<DataFile> dataFiles) { logger.debug("Adding data files to the bdoc zip container"); for (DataFile dataFile : dataFiles) { String name = dataFile.getName(); logger.debug("Adding data file " + name); ZipEntry entryDocument = new ZipEntry(name); zipOutputStream.setLevel(ZipEntry.DEFLATED); byte[] entryBytes = dataFile.getBytes(); writeZipEntry(entryDocument, entryBytes); }/*from w ww . j a v a 2 s. c o m*/ }
From source file:org.digidoc4j.impl.bdoc.asic.AsicContainerCreator.java
public void writeExistingEntries(Collection<AsicEntry> asicEntries) { logger.debug("Writing existing zip container entries"); for (AsicEntry asicEntry : asicEntries) { DSSDocument content = asicEntry.getContent(); byte[] entryBytes = getDocumentBytes(content); ZipEntry zipEntry = asicEntry.getZipEntry(); if (!StringUtils.equalsIgnoreCase(ZIP_ENTRY_MIMETYPE, zipEntry.getName())) { zipOutputStream.setLevel(ZipEntry.DEFLATED); }//from w w w . j a v a2 s. c o m writeZipEntryWithoutComment(zipEntry, entryBytes); } }
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) *///w w w . j av a 2 s. co m @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.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 w w w .ja v a 2 s . c o m*/ } } }
From source file:org.omegat.filters3.xml.opendoc.OpenDocFilter.java
/** * Processes a single OpenDocument file, which is actually a ZIP file consisting of many XML files, some * of which should be translated./*from ww w . ja va 2 s . c o m*/ */ @Override public void processFile(File inFile, File outFile, FilterContext fc) throws IOException, TranslationException { ZipFile zipfile = new ZipFile(inFile); ZipOutputStream zipout = null; if (outFile != null) zipout = new ZipOutputStream(new FileOutputStream(outFile)); Enumeration<? extends ZipEntry> zipcontents = zipfile.entries(); while (zipcontents.hasMoreElements()) { ZipEntry zipentry = zipcontents.nextElement(); String shortname = zipentry.getName(); if (shortname.lastIndexOf('/') >= 0) shortname = shortname.substring(shortname.lastIndexOf('/') + 1); if (TRANSLATABLE.contains(shortname)) { File tmpin = tmp(); FileUtils.copyInputStreamToFile(zipfile.getInputStream(zipentry), tmpin); File tmpout = null; if (zipout != null) tmpout = tmp(); try { createXMLFilter(processOptions).processFile(tmpin, tmpout, fc); } catch (Exception e) { zipfile.close(); throw new TranslationException( e.getLocalizedMessage() + "\n" + OStrings.getString("OpenDoc_ERROR_IN_FILE") + inFile); } if (zipout != null) { ZipEntry outentry = new ZipEntry(zipentry.getName()); outentry.setMethod(ZipEntry.DEFLATED); zipout.putNextEntry(outentry); FileUtils.copyFile(tmpout, zipout); zipout.closeEntry(); } if (!tmpin.delete()) tmpin.deleteOnExit(); if (tmpout != null) { if (!tmpout.delete()) tmpout.deleteOnExit(); } } else { if (zipout != null) { ZipEntry outentry = new ZipEntry(zipentry.getName()); zipout.putNextEntry(outentry); IOUtils.copy(zipfile.getInputStream(zipentry), zipout); zipout.closeEntry(); } } } if (zipout != null) zipout.close(); zipfile.close(); }
From source file:org.sead.nds.repository.BagGenerator.java
private void createDir(final String name) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(name); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { return new ByteArrayInputStream(("").getBytes()); }//from w ww.j a v a 2s . com }; addEntry(archiveEntry, supp); }
From source file:org.sead.nds.repository.BagGenerator.java
private void createFileFromString(final String name, final String content) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(name); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { try { return new ByteArrayInputStream(content.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace();// ww w.ja v a 2 s .c om } return null; } }; addEntry(archiveEntry, supp); }