List of usage examples for org.apache.commons.compress.archivers.zip ZipArchiveOutputStream closeArchiveEntry
public void closeArchiveEntry() throws IOException
From source file:org.apache.james.mailbox.backup.Zipper.java
private void storeInArchive(Mailbox mailbox, ZipArchiveOutputStream archiveOutputStream) throws IOException { String name = mailbox.getName(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new Directory(name), name);//from w w w . j a v a 2 s . c o m archiveEntry.addExtraField(new MailboxIdExtraField(mailbox.getMailboxId().serialize())); archiveEntry.addExtraField(new UidValidityExtraField(mailbox.getUidValidity())); archiveOutputStream.putArchiveEntry(archiveEntry); archiveOutputStream.closeArchiveEntry(); }
From source file:org.apache.james.mailbox.backup.Zipper.java
private void storeInArchive(MailboxMessage message, ZipArchiveOutputStream archiveOutputStream) throws IOException { String entryId = message.getMessageId().serialize(); ZipArchiveEntry archiveEntry = (ZipArchiveEntry) archiveOutputStream.createArchiveEntry(new File(entryId), entryId);/*w ww .ja va 2s .co m*/ archiveEntry.addExtraField(new SizeExtraField(message.getFullContentOctets())); archiveEntry.addExtraField(new UidExtraField(message.getUid().asLong())); archiveEntry.addExtraField(new MessageIdExtraField(message.getMessageId().serialize())); archiveEntry.addExtraField(new MailboxIdExtraField(message.getMailboxId().serialize())); archiveEntry.addExtraField(new InternalDateExtraField(message.getInternalDate())); archiveEntry.addExtraField(new FlagsExtraField(message.createFlags())); archiveOutputStream.putArchiveEntry(archiveEntry); IOUtils.copy(message.getFullContent(), archiveOutputStream); archiveOutputStream.closeArchiveEntry(); }
From source file:org.apache.karaf.tooling.ArchiveMojo.java
private void addFileToZip(ZipArchiveOutputStream tOut, Path f, String base) throws IOException { if (Files.isDirectory(f)) { String entryName = base + f.getFileName().toString() + "/"; ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); tOut.putArchiveEntry(zipEntry);/*from w w w . j a va 2 s .co m*/ tOut.closeArchiveEntry(); try (DirectoryStream<Path> children = Files.newDirectoryStream(f)) { for (Path child : children) { addFileToZip(tOut, child, entryName); } } } else if (useSymLinks && Files.isSymbolicLink(f)) { String entryName = base + f.getFileName().toString(); ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); zipEntry.setUnixMode(UnixStat.LINK_FLAG | UnixStat.DEFAULT_FILE_PERM); tOut.putArchiveEntry(zipEntry); tOut.write(Files.readSymbolicLink(f).toString().getBytes()); tOut.closeArchiveEntry(); } else { String entryName = base + f.getFileName().toString(); ZipArchiveEntry zipEntry = new ZipArchiveEntry(entryName); zipEntry.setSize(Files.size(f)); if (entryName.contains("/bin/") || (!usePathPrefix && entryName.startsWith("bin"))) { if (!entryName.endsWith(".bat")) { zipEntry.setUnixMode(0755); } else { zipEntry.setUnixMode(0644); } } tOut.putArchiveEntry(zipEntry); Files.copy(f, tOut); tOut.closeArchiveEntry(); } }
From source file:org.apache.openejb.maven.plugin.BuildTomEEMojo.java
private void zip(final ZipArchiveOutputStream zip, final File f, final String prefix) throws IOException { final String path = f.getPath().replace(prefix, "").replace(File.separator, "/"); final ZipArchiveEntry archiveEntry = new ZipArchiveEntry(f, path); if (isSh(path)) { archiveEntry.setUnixMode(0755);/* w w w .ja v a 2 s . c o m*/ } zip.putArchiveEntry(archiveEntry); if (f.isDirectory()) { zip.closeArchiveEntry(); final File[] files = f.listFiles(); if (files != null) { for (final File child : files) { zip(zip, child, prefix); } } } else { IO.copy(f, zip); zip.closeArchiveEntry(); } }
From source file:org.apache.sis.internal.maven.Assembler.java
/** * Creates the distribution file.//w w w . j a v a 2s . c o m * * @throws MojoExecutionException if the plugin execution failed. */ @Override public void execute() throws MojoExecutionException { final File sourceDirectory = new File(rootDirectory, ARTIFACT_PATH); if (!sourceDirectory.isDirectory()) { throw new MojoExecutionException("Directory not found: " + sourceDirectory); } final File targetDirectory = new File(rootDirectory, TARGET_DIRECTORY); final String version = project.getVersion(); final String artifactBase = FINALNAME_PREFIX + version; try { final File targetFile = new File(distributionDirectory(targetDirectory), artifactBase + ".zip"); final ZipArchiveOutputStream zip = new ZipArchiveOutputStream(targetFile); try { zip.setLevel(9); appendRecursively(sourceDirectory, artifactBase, zip, new byte[8192]); /* * At this point, all the "application/sis-console/src/main/artifact" and sub-directories * have been zipped. Now generate the Pack200 file and zip it directly (without creating * a temporary "sis.pack.gz" file). */ final Packer packer = new Packer(project.getName(), project.getUrl(), version, targetDirectory); final ZipArchiveEntry entry = new ZipArchiveEntry( artifactBase + '/' + LIB_DIRECTORY + '/' + FATJAR_FILE + PACK_EXTENSION); entry.setMethod(ZipArchiveEntry.STORED); zip.putArchiveEntry(entry); packer.preparePack200(FATJAR_FILE + ".jar").pack(new FilterOutputStream(zip) { /* * Closes the archive entry, not the ZIP file. */ @Override public void close() throws IOException { zip.closeArchiveEntry(); } }); } finally { zip.close(); } } catch (IOException e) { throw new MojoExecutionException(e.getLocalizedMessage(), e); } }
From source file:org.apache.sis.internal.maven.Assembler.java
/** * Adds the given file in the ZIP file. If the given file is a directory, then this method * recursively adds all files contained in this directory. This method is invoked for zipping * the "application/sis-console/src/main/artifact" directory and sub-directories before to zip * the Pack200 file./*ww w . ja va 2 s .com*/ */ private void appendRecursively(final File file, String relativeFile, final ZipArchiveOutputStream out, final byte[] buffer) throws IOException { if (file.isDirectory()) { relativeFile += '/'; } final ZipArchiveEntry entry = new ZipArchiveEntry(file, relativeFile); if (file.canExecute()) { entry.setUnixMode(0744); } out.putArchiveEntry(entry); if (!entry.isDirectory()) { final FileInputStream in = new FileInputStream(file); try { int n; while ((n = in.read(buffer)) >= 0) { out.write(buffer, 0, n); } } finally { in.close(); } } out.closeArchiveEntry(); if (entry.isDirectory()) { for (final String filename : file.list(this)) { appendRecursively(new File(file, filename), relativeFile.concat(filename), out, buffer); } } }
From source file:org.apache.slider.tools.TestUtility.java
public static void addDir(File dirObj, ZipArchiveOutputStream zipFile, String prefix) throws IOException { for (File file : dirObj.listFiles()) { if (file.isDirectory()) { addDir(file, zipFile, prefix + file.getName() + File.separator); } else {/* w w w. ja v a 2 s . co m*/ log.info("Adding to zip - " + prefix + file.getName()); zipFile.putArchiveEntry(new ZipArchiveEntry(prefix + file.getName())); IOUtils.copy(new FileInputStream(file), zipFile); zipFile.closeArchiveEntry(); } } }
From source file:org.apache.tika.server.writer.ZipWriter.java
private static void zipStoreBuffer(ZipArchiveOutputStream zip, String name, byte[] dataBuffer) throws IOException { ZipEntry zipEntry = new ZipEntry(name != null ? name : UUID.randomUUID().toString()); zipEntry.setMethod(ZipOutputStream.STORED); zipEntry.setSize(dataBuffer.length); CRC32 crc32 = new CRC32(); crc32.update(dataBuffer);//from w w w.j av a2 s. c o m zipEntry.setCrc(crc32.getValue()); try { zip.putArchiveEntry(new ZipArchiveEntry(zipEntry)); } catch (ZipException ex) { if (name != null) { zipStoreBuffer(zip, "x-" + name, dataBuffer); return; } } zip.write(dataBuffer); zip.closeArchiveEntry(); }
From source file:org.beangle.commons.archiver.ZipUtils.java
public static File zip(List<String> fileNames, String zipPath, String encoding) { try {/*from w w w . j a va 2 s .c o m*/ FileOutputStream f = new FileOutputStream(zipPath); ZipArchiveOutputStream zos = (ZipArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, f); if (null != encoding) { zos.setEncoding(encoding); } for (int i = 0; i < fileNames.size(); i++) { String fileName = fileNames.get(i); String entryName = StringUtils.substringAfterLast(fileName, File.separator); ZipArchiveEntry entry = new ZipArchiveEntry(entryName); zos.putArchiveEntry(entry); FileInputStream fis = new FileInputStream(fileName); IOUtils.copy(fis, zos); fis.close(); zos.closeArchiveEntry(); } zos.close(); return new File(zipPath); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.beangle.ems.util.ZipUtils.java
/** * <p>/*from ww w . jav a 2 s . co m*/ * zip. * </p> * * @param fileNames a {@link java.util.List} object. * @param zipPath a {@link java.lang.String} object. * @param encoding a {@link java.lang.String} object. * @return a {@link java.io.File} object. */ public static File zip(List<String> fileNames, String zipPath, String encoding) { try { FileOutputStream f = new FileOutputStream(zipPath); ZipArchiveOutputStream zos = (ZipArchiveOutputStream) new ArchiveStreamFactory() .createArchiveOutputStream(ArchiveStreamFactory.ZIP, f); if (null != encoding) { zos.setEncoding(encoding); } for (int i = 0; i < fileNames.size(); i++) { String fileName = fileNames.get(i); String entryName = Strings.substringAfterLast(fileName, File.separator); ZipArchiveEntry entry = new ZipArchiveEntry(entryName); zos.putArchiveEntry(entry); FileInputStream fis = new FileInputStream(fileName); IOs.copy(fis, zos); fis.close(); zos.closeArchiveEntry(); } zos.close(); return new File(zipPath); } catch (Exception e) { throw new RuntimeException(e); } }