Java Code Examples for java.util.zip.ZipOutputStream#finish()
The following examples show how to use
java.util.zip.ZipOutputStream#finish() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArchiveBleach.java From DocBleach with MIT License | 6 votes |
@Override public void sanitize(InputStream inputStream, OutputStream outputStream, BleachSession session) throws BleachException { ZipInputStream zipIn = new ZipInputStream(inputStream); ZipOutputStream zipOut = new ZipOutputStream(outputStream); try { ZipEntry entry; while ((entry = zipIn.getNextEntry()) != null) { if (entry.isDirectory()) { LOGGER.trace("Directory: {}", entry.getName()); ZipEntry newEntry = new ZipEntry(entry); zipOut.putNextEntry(newEntry); } else { LOGGER.trace("Entry: {}", entry.getName()); sanitizeFile(session, zipIn, zipOut, entry); } zipOut.closeEntry(); } zipOut.finish(); } catch (IOException e) { LOGGER.error("Error in ArchiveBleach", e); } }
Example 2
Source File: LocalStore.java From hadoop-gpu with Apache License 2.0 | 6 votes |
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
Example 3
Source File: TransferServiceImpl.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@Override public void exportAll ( final OutputStream stream ) throws IOException { final ZipOutputStream zos = new ZipOutputStream ( stream ); initExportFile ( zos ); final Collection<? extends ChannelId> ids = this.channelService.list (); // TODO: run exportAll inside a channel service lock for ( final ChannelId channelId : ids ) { zos.putNextEntry ( new ZipEntry ( String.format ( "%s.zip", channelId.getId () ) ) ); exportChannel ( By.id ( channelId.getId () ), zos ); zos.closeEntry (); } zos.finish (); }
Example 4
Source File: ZipFiles.java From beam with Apache License 2.0 | 6 votes |
/** * Zips an entire directory specified by the path. * * @param sourceDirectory the directory to read from. This directory and all subdirectories will * be added to the zip-file. The path within the zip file is relative to the directory given * as parameter, not absolute. * @param outputStream the stream to write the zip-file to. This method does not close * outputStream. * @throws IOException the zipping failed, e.g. because the input was not readable. */ public static void zipDirectory(File sourceDirectory, OutputStream outputStream) throws IOException { checkNotNull(sourceDirectory); checkNotNull(outputStream); checkArgument( sourceDirectory.isDirectory(), "%s is not a valid directory", sourceDirectory.getAbsolutePath()); ZipOutputStream zos = new ZipOutputStream(outputStream); for (File file : sourceDirectory.listFiles()) { zipDirectoryInternal(file, "", zos); } zos.finish(); }
Example 5
Source File: B7050028.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 6
Source File: B7050028.java From hottub with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 7
Source File: B7050028.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 8
Source File: B7050028.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 9
Source File: LocalStore.java From RDFS with Apache License 2.0 | 6 votes |
/** * Compress a text file using the ZIP compressing algorithm. * * @param filename the path to the file to be compressed */ public static void zipCompress(String filename) throws IOException { FileOutputStream fos = new FileOutputStream(filename + COMPRESSION_SUFFIX); CheckedOutputStream csum = new CheckedOutputStream(fos, new CRC32()); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(csum)); out.setComment("Failmon records."); BufferedReader in = new BufferedReader(new FileReader(filename)); out.putNextEntry(new ZipEntry(new File(filename).getName())); int c; while ((c = in.read()) != -1) out.write(c); in.close(); out.finish(); out.close(); }
Example 10
Source File: ClientExport.java From orion.server with Eclipse Public License 1.0 | 6 votes |
public void doExport(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { IFileStore source = NewFileServlet.getFileStore(req, sourcePath); if (req.getParameter(ProtocolConstants.PARAM_EXCLUDE) != null) { excludedFiles = Arrays.asList(req.getParameter(ProtocolConstants.PARAM_EXCLUDE).split(",")); } try { if (source.fetchInfo(EFS.NONE, null).isDirectory() && source.childNames(EFS.NONE, null).length == 0) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "You cannot export an empty folder"); return; } resp.setHeader("Cache-Control", "no-cache"); //$NON-NLS-1$ //$NON-NLS-2$ ZipOutputStream zout = new ZipOutputStream(resp.getOutputStream()); write(source, Path.EMPTY, zout); zout.finish(); } catch (CoreException e) { //we can't return an error response at this point because the output stream has been used throw new ServletException(e); } }
Example 11
Source File: AbstractZip.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ public void zipEntries(OutputStream os) throws IOException { ZipOutputStream zipos = new ZipOutputStream(os); zipos.setMethod(ZipOutputStream.DEFLATED); for (String name : exportZipEntries.keySet()) { ExportZipEntry exportZipEntry = exportZipEntries.get(name); ZipEntry zipEntry = new ZipEntry(exportZipEntry.getName()); zipos.putNextEntry(zipEntry); exportZipEntry.writeData(zipos); } zipos.flush(); zipos.finish(); }
Example 12
Source File: B7050028.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 13
Source File: B7050028.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { URLConnection conn = B7050028.class.getResource("B7050028.class").openConnection(); int len = conn.getContentLength(); byte[] data = new byte[len]; InputStream is = conn.getInputStream(); is.read(data); is.close(); conn.setDefaultUseCaches(false); File jar = File.createTempFile("B7050028", ".jar"); jar.deleteOnExit(); OutputStream os = new FileOutputStream(jar); ZipOutputStream zos = new ZipOutputStream(os); ZipEntry ze = new ZipEntry("B7050028.class"); ze.setMethod(ZipEntry.STORED); ze.setSize(len); CRC32 crc = new CRC32(); crc.update(data); ze.setCrc(crc.getValue()); zos.putNextEntry(ze); zos.write(data, 0, len); zos.closeEntry(); zos.finish(); zos.close(); os.close(); System.out.println(new URLClassLoader(new URL[] {new URL("jar:" + jar.toURI() + "!/")}, ClassLoader.getSystemClassLoader().getParent()).loadClass(B7050028.class.getName())); }
Example 14
Source File: ZipFileUtils.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a ZIP file and returns the bytes for a given mapping of file name to file content. * * @param files the file map from name to content. * @return the bytes of a ZIP file * @throws IOException when creating the zip file fails at any point. */ public static byte[] zipFiles(Map<String, byte[]> files) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ZipOutputStream zos = new ZipOutputStream(baos); for (String fileName : files.keySet()) { final ZipEntry e = new ZipEntry(fileName); try { zos.putNextEntry(e); zos.write(files.get(fileName)); zos.closeEntry(); } catch (Exception entryException) { logger.error("Failed to add file to ZIP file.", entryException); } } zos.finish(); zos.close(); final byte[] bytes = baos.toByteArray(); baos.close(); return bytes; }
Example 15
Source File: ZipCompressionOutputStream.java From hop with Apache License 2.0 | 5 votes |
@Override public void close() throws IOException { ZipOutputStream zos = (ZipOutputStream) delegate; zos.flush(); zos.closeEntry(); zos.finish(); zos.close(); }
Example 16
Source File: AbstractWriter.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public void write ( final OutputStream stream ) throws IOException { if ( this.compressed ) { final ZipOutputStream zos = new ZipOutputStream ( stream ); zos.putNextEntry ( new ZipEntry ( this.basename + ".xml" ) ); writeAll ( zos ); zos.closeEntry (); zos.finish (); } else { writeAll ( stream ); } }
Example 17
Source File: ZipUtil.java From ant-ivy with Apache License 2.0 | 5 votes |
public static void zip(File sourceDir, OutputStream targetStream) throws IOException { if (!sourceDir.isFile() && !sourceDir.isDirectory()) { return; } final ZipOutputStream cpZipOutputStream = new ZipOutputStream(targetStream); cpZipOutputStream.setLevel(9); zipFiles(sourceDir, sourceDir, cpZipOutputStream); cpZipOutputStream.finish(); cpZipOutputStream.close(); }
Example 18
Source File: ZipDatasets.java From java-samples with Apache License 2.0 | 5 votes |
/** * Process the given input datasets and create a Zip archive on the * given output file or dataset. */ public int run() throws IOException { ZipOutputStream zipOutStream = openZipOutputStream(); try { processInputFiles(zipOutStream); zipOutStream.finish(); System.out.println(" done: " + errors + " errors"); return errors; } finally { try { zipOutStream.close(); } catch (Throwable ignore) {} } }
Example 19
Source File: StreamUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Finishes writing the contents of the ZIP output stream without closing the underlying stream. * * @param out the ZipOutputStream. */ public static void finishZipEntry( ZipOutputStream out ) { try { out.finish(); } catch ( Exception ex ) { throw new RuntimeException( "Failed to finish the content of the ZipOutputStream", ex ); } }
Example 20
Source File: RepositoryUtilities.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 3 votes |
/** * Writes the given repository as ZIP-File into the given output stream. * * @param outputStream the output stream that should receive the zipfile. * @param repository the repository that should be written. * @throws IOException if an IO error prevents the writing of the file. * @throws ContentIOException if a repository related IO error occurs. */ public static void writeAsZip( final OutputStream outputStream, final Repository repository ) throws IOException, ContentIOException { final ZipOutputStream zipout = new ZipOutputStream( outputStream ); writeToZipStream( zipout, repository ); zipout.finish(); zipout.flush(); }