@Override public void close() throws IOException { ZipOutputStream zos = (ZipOutputStream) delegate; zos.flush(); zos.closeEntry(); zos.finish(); zos.close(); }
/** * Zip the files. * * @param srcFiles The source of files. * @param zipFile The ZIP file. * @param comment The comment. * @return {@code true}: success<br>{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection<File> srcFiles, final File zipFile, final String comment) throws IOException { if (srcFiles == null || zipFile == null) return false; ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFile)); for (File srcFile : srcFiles) { if (!zipFile(srcFile, "", zos, comment)) return false; } return true; } finally { if (zos != null) { zos.finish(); zos.close(); } } }
/** * Closes the current {@code ZipEntry}, if any, and the underlying output * stream. If the stream is already closed this method does nothing. * * @throws IOException * If an error occurs closing the stream. */ @Override public void close() throws IOException { // don't call super.close() because that calls finish() conditionally if (out != null) { finish(); def.end(); out.close(); out = null; } }
/** * Zip the files. * * @param srcFilePaths The paths of source files. * @param zipFilePath The path of ZIP file. * @param comment The comment. * @return {@code true}: success<br>{@code false}: fail * @throws IOException if an I/O error has occurred */ public static boolean zipFiles(final Collection<String> srcFilePaths, final String zipFilePath, final String comment) throws IOException { if (srcFilePaths == null || zipFilePath == null) return false; ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(zipFilePath)); for (String srcFile : srcFilePaths) { if (!zipFile(getFileByPath(srcFile), "", zos, comment)) return false; } return true; } finally { if (zos != null) { zos.finish(); zos.close(); } } }
private boolean closeFile() { boolean retval = false; if ( data.OpenedNewFile ) { try { // Close the parent element data.writer.writeEndElement(); data.writer.writeCharacters( EOL ); // System.out.println("Closed xml file..."); data.writer.writeEndDocument(); data.writer.close(); if ( meta.isZipped() ) { // System.out.println("close zip entry "); data.zip.closeEntry(); // System.out.println("finish file..."); data.zip.finish(); data.zip.close(); } closeOutputStream( outputStream ); retval = true; } catch ( Exception e ) { // Ignore errors } } return retval; }
private static void pack(ZipEntrySource[] entries, OutputStream os, boolean closeStream) { try { ZipOutputStream out = new ZipOutputStream(os); for (int i = 0; i < entries.length; i++) { addEntry(entries[i], out); } out.flush(); out.finish(); if (closeStream) { out.close(); } } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } }
/** * Copies an existing ZIP file and appends it with new entries. * * @param zip * an existing ZIP file (only read). * @param entries * new ZIP entries appended. * @param destOut * new ZIP destination output stream */ public static void addEntries(File zip, ZipEntrySource[] entries, OutputStream destOut) { if (log.isDebugEnabled()) { log.debug("Copying '" + zip + "' to a stream and adding " + Arrays.asList(entries) + "."); } ZipOutputStream out = null; try { out = new ZipOutputStream(destOut); copyEntries(zip, out); for (int i = 0; i < entries.length; i++) { addEntry(entries[i], out); } out.finish(); } catch (IOException e) { ZipExceptionUtil.rethrow(e); } }
/** * Copies an existing ZIP file and appends it with new entries. * * @param is * an existing ZIP input stream. * @param entries * new ZIP entries appended. * @param destOut * new ZIP destination output stream * * @since 1.9 */ public static void addEntries(InputStream is, ZipEntrySource[] entries, OutputStream destOut) { if (log.isDebugEnabled()) { log.debug("Copying input stream to an output stream and adding " + Arrays.asList(entries) + "."); } ZipOutputStream out = null; try { out = new ZipOutputStream(destOut); copyEntries(is, out); for (int i = 0; i < entries.length; i++) { addEntry(entries[i], out); } out.finish(); } catch (IOException e) { ZipExceptionUtil.rethrow(e); } }
/** * Copies an existing ZIP file and transforms the given entries in it. * * @param is * a ZIP input stream. * @param entries * ZIP entry transformers. * @param os * a ZIP output stream. * @return <code>true</code> if at least one entry was replaced. */ public static boolean transformEntries(InputStream is, ZipEntryTransformerEntry[] entries, OutputStream os) { if (log.isDebugEnabled()) log.debug("Copying '" + is + "' to '" + os + "' and transforming entries " + Arrays.asList(entries) + "."); try { ZipOutputStream out = new ZipOutputStream(os); TransformerZipEntryCallback action = new TransformerZipEntryCallback(Arrays.asList(entries), out); iterate(is, action); // Finishes writing the contents of the ZIP output stream without closing // the underlying stream. out.finish(); return action.found(); } catch (IOException e) { throw ZipExceptionUtil.rethrow(e); } }
zipOutputStream.finish(); } catch (IOException e) { throw new FileUtilException(e);
try { if (zipOutputStream != null) { zipOutputStream.finish(); zipOutputStream.flush(); zipOutputStream.close();
if (out != null && error == null) { try { out.finish(); out.flush();
@Override public void process(final OutputStream rawOut) throws IOException { try (final OutputStream bufferedOut = new BufferedOutputStream(rawOut); final ZipOutputStream out = new ZipOutputStream(bufferedOut)) { out.setLevel(compressionLevel); for (final FlowFile flowFile : contents) { final String path = keepPath ? getPath(flowFile) : ""; final String entryName = path + flowFile.getAttribute(CoreAttributes.FILENAME.key()); final ZipEntry zipEntry = new ZipEntry(entryName); zipEntry.setSize(flowFile.getSize()); try { out.putNextEntry(zipEntry); bin.getSession().exportTo(flowFile, out); out.closeEntry(); unmerged.remove(flowFile); } catch (ZipException e) { getLogger().error("Encountered exception merging {}", new Object[] {flowFile}, e); } } out.finish(); out.flush(); } } });
zipOutputStream.finish(); zipOutputStream.close(); } catch ( IOException e ) {
if ( zipOutputStream != null ) { try { zipOutputStream.finish(); zipOutputStream.close(); } catch ( IOException e ) {
/** * Zip a list of blob. * * @param blobs the blob list * @param fileName if no filename is given, the first blob's filename will be used * @return a zip containing the list of blob * @throws IOException */ public static Blob zip(List<Blob> blobs, String fileName) throws IOException { if (fileName == null || (fileName = fileName.trim()).length() == 0) { fileName = blobs.isEmpty() ? null : blobs.get(0).getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blobs, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, fileName); }
/** * Zip the given blob. * * @param blob the blob * @param filename if no filename is given, the blob's filename will be used * @return a zip containing the blob * @throws IOException */ public static Blob zip(Blob blob, String filename) throws IOException { if (filename == null || (filename = filename.trim()).length() == 0) { filename = blob.getFilename(); } File file = Framework.createTempFile("nxops-createzip-", ".tmp"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); Framework.trackFile(file, file); try { zip(blob, out); } finally { out.finish(); out.close(); } return Blobs.createBlob(file, "application/zip", null, filename); }
zip.finish(); zip.flush();