List of usage examples for java.util.zip ZipEntry ZipEntry
public ZipEntry(ZipEntry e)
From source file:com.espringtran.compressor4j.processor.Bzip2Processor.java
/** * Compress data/*w w w .jav a 2 s . c o m*/ * * @param fileCompressor * FileCompressor object * @return * @throws Exception */ @Override public byte[] compressData(FileCompressor fileCompressor) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos); ZipOutputStream zos = new ZipOutputStream(cos); try { zos.setLevel(fileCompressor.getLevel().getValue()); zos.setMethod(ZipOutputStream.DEFLATED); zos.setComment(fileCompressor.getComment()); for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile().values()) { zos.putNextEntry(new ZipEntry(binaryFile.getDesPath())); zos.write(binaryFile.getData()); zos.closeEntry(); } zos.flush(); zos.finish(); } catch (Exception e) { FileCompressor.LOGGER.error("Error on compress data", e); } finally { zos.close(); cos.close(); baos.close(); } return baos.toByteArray(); }
From source file:abfab3d.io.output.SVXWriter.java
/** * Writes a grid out to an svx file/*from ww w. ja v a 2 s.co m*/ * @param grid * @param os */ public void write(AttributeGrid grid, OutputStream os) { ZipOutputStream zos = null; try { zos = new ZipOutputStream(os); ZipEntry zentry = new ZipEntry("manifest.xml"); zos.putNextEntry(zentry); writeManifest(grid, zos); zos.closeEntry(); SlicesWriter sw = new SlicesWriter(); AttributeDesc attDesc = grid.getAttributeDesc(); for (int i = 0; i < attDesc.size(); i++) { AttributeChannel channel = attDesc.getChannel(i); String channelPattern = channel.getName() + "/" + "slice%04d.png"; sw.writeSlices(grid, zos, channelPattern, 0, 0, getSlicesCount(grid), m_orientation, channel.getBitCount(), channel); } } catch (IOException ioe) { ioe.printStackTrace(); } finally { IOUtils.closeQuietly(zos); } }
From source file:com.microsoft.azurebatch.jenkins.utils.ZipHelper.java
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, boolean isEmptyFolder) throws IOException { File folder = new File(srcFile); if (isEmptyFolder == true) { zip.putNextEntry(new ZipEntry(path + "/" + folder.getName() + "/")); } else {//from w w w.j av a 2s . c o m if (folder.isDirectory()) { addFolderToZip(path, srcFile, zip); } else { byte[] buf = new byte[1024]; int len; try (FileInputStream in = new FileInputStream(srcFile)) { zip.putNextEntry(new ZipEntry(path + "/" + folder.getName())); while ((len = in.read(buf)) > 0) { zip.write(buf, 0, len); } } } } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.util.ArchiveCompressorZipImpl.java
/** * Compress the given files into an archive with the given name, plus the file extension. Put the compressed * archive into the given directory./*from www. j a v a 2 s . co m*/ * * @param files the files to include in the archive * @param archiveName the name of the archive, minus extension * @param destinationDirectory the location to put the new compressed archive * @param compress flag to compress the archive * @return the File representing the created compressed archive * @throws IOException if it needs to */ public File createArchive(final List<File> files, final String archiveName, final File destinationDirectory, final Boolean compress) throws IOException { final File archiveFile = new File(destinationDirectory, archiveName + ZIP_EXTENSION); ZipOutputStream out = null; FileInputStream in = null; try { //noinspection IOResourceOpenedButNotSafelyClosed out = new ZipOutputStream(new FileOutputStream(archiveFile)); final byte[] buf = new byte[1024]; for (final File file : files) { try { //noinspection IOResourceOpenedButNotSafelyClosed in = new FileInputStream(file); out.putNextEntry(new ZipEntry(archiveName + File.separator + file.getName())); int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); in.close(); } finally { IOUtils.closeQuietly(in); } } } finally { IOUtils.closeQuietly(out); } return archiveFile; }
From source file:com.xpn.xwiki.plugin.packaging.AbstractPackageTest.java
/** * Create a XAR file using java.util.zip. * * @param docs The documents to include. * @param encodings The charset for each document. * @param packageXmlEncoding The encoding of package.xml * @return the XAR file as a byte array. *//*from w ww. j a va2 s . c o m*/ protected byte[] createZipFile(XWikiDocument docs[], String[] encodings, String packageXmlEncoding) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); ZipEntry zipp = new ZipEntry("package.xml"); zos.putNextEntry(zipp); zos.write(getEncodedByteArray(getPackageXML(docs, packageXmlEncoding), packageXmlEncoding)); for (int i = 0; i < docs.length; i++) { String zipEntryName = docs[i].getSpace() + "/" + docs[i].getName(); if (docs[i].getTranslation() != 0) { zipEntryName += "." + docs[i].getLanguage(); } ZipEntry zipe = new ZipEntry(zipEntryName); zos.putNextEntry(zipe); String xmlCode = docs[i].toXML(false, false, false, false, getContext()); zos.write(getEncodedByteArray(xmlCode, encodings[i])); } zos.finish(); zos.close(); return baos.toByteArray(); }
From source file:com.formkiq.core.util.Zips.java
/** * Create Zip file.//ww w .j av a2 s.c om * @param map {@link Map} * @return byte[] zip file * @throws IOException IOException */ public static byte[] zipFile(final Map<String, byte[]> map) throws IOException { ByteArrayOutputStream bs = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(bs); for (Map.Entry<String, byte[]> e : map.entrySet()) { String name = e.getKey(); byte[] data = e.getValue(); ZipEntry ze = new ZipEntry(name); zip.putNextEntry(ze); zip.write(data, 0, data.length); zip.closeEntry(); } zip.finish(); byte[] bytes = bs.toByteArray(); IOUtils.closeQuietly(bs); IOUtils.closeQuietly(zip); return bytes; }
From source file:com.headwire.aem.tooling.intellij.eclipse.stub.JarBuilder.java
public InputStream buildJar(final IFolder sourceDir) throws CoreException { ByteArrayOutputStream store = new ByteArrayOutputStream(); JarOutputStream zos = null;/* w w w . j ava2 s .c om*/ InputStream manifestInput = null; try { IResource manifestResource = sourceDir.findMember(JarFile.MANIFEST_NAME); if (manifestResource == null || manifestResource.getType() != IResource.FILE) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "No file named " + JarFile.MANIFEST_NAME + " found under " + sourceDir)); } manifestInput = ((IFile) manifestResource).getContents(); Manifest manifest = new Manifest(manifestInput); zos = new JarOutputStream(store); zos.setLevel(Deflater.NO_COMPRESSION); // manifest first final ZipEntry anEntry = new ZipEntry(JarFile.MANIFEST_NAME); zos.putNextEntry(anEntry); manifest.write(zos); zos.closeEntry(); zipDir(sourceDir, zos, ""); } catch (IOException e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); } finally { IOUtils.closeQuietly(zos); IOUtils.closeQuietly(manifestInput); } return new ByteArrayInputStream(store.toByteArray()); }
From source file:net.sourceforge.floggy.maven.ZipUtils.java
/** * DOCUMENT ME!//from w ww. j av a 2 s. c o m * * @param directories DOCUMENT ME! * @param output DOCUMENT ME! * * @throws IOException DOCUMENT ME! */ public static void zip(File[] directories, File output) throws IOException { FileInputStream in = null; ZipOutputStream out = null; ZipEntry entry = null; Collection allFiles = new LinkedList(); for (int i = 0; i < directories.length; i++) { allFiles.addAll(FileUtils.listFiles(directories[i], null, true)); } out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(output))); for (Iterator iter = allFiles.iterator(); iter.hasNext();) { File temp = (File) iter.next(); String name = getEntryName(directories, temp.getAbsolutePath()); entry = new ZipEntry(name); out.putNextEntry(entry); if (!temp.isDirectory()) { in = new FileInputStream(temp); IOUtils.copy(in, out); in.close(); } } out.close(); }
From source file:com.c4om.autoconf.ulysses.configanalyzer.packager.ZipConfigurationPackager.java
/** * This implementation compresses files into a ZIP file * @see com.c4om.autoconf.ulysses.interfaces.configanalyzer.packager.CompressedFileConfigurationPackager#compressFiles(java.io.File, java.util.List, java.io.File) *///from w w w . ja v a2 s .co m @Override protected void compressFiles(File actualRootFolder, List<String> entries, File zipFile) throws FileNotFoundException, IOException { //We use the FileUtils method so that necessary directories are automatically created. FileOutputStream zipFOS = FileUtils.openOutputStream(zipFile); ZipOutputStream zos = new ZipOutputStream(zipFOS); for (String entry : entries) { ZipEntry ze = new ZipEntry(entry); zos.putNextEntry(ze); FileInputStream sourceFileIN = new FileInputStream( actualRootFolder.getAbsolutePath() + File.separator + entry); IOUtils.copy(sourceFileIN, zos); sourceFileIN.close(); } zos.closeEntry(); zos.close(); }
From source file:com.compomics.pladipus.core.control.util.ZipUtils.java
/** * Zips a single file to the specified folder * * @param input the original folder/*from www . j a v a 2 s. co m*/ * @param output the destination zip file */ public static void zipFile(File inputFile, File zipFile) { try (FileInputStream fileInputStream = new FileInputStream(inputFile); FileOutputStream fileOutputStream = new FileOutputStream(zipFile); ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) { ZipEntry zipEntry = new ZipEntry(inputFile.getName()); zipOutputStream.putNextEntry(zipEntry); byte[] buf = new byte[1024]; int bytesRead; // Read the input file by chucks of 1024 bytes // and write the read bytes to the zip stream while ((bytesRead = fileInputStream.read(buf)) > 0) { zipOutputStream.write(buf, 0, bytesRead); } // close ZipEntry to store the stream to the file zipOutputStream.closeEntry(); LOGGER.debug("Regular file :" + inputFile.getCanonicalPath() + " is zipped to archive :" + zipFile.getAbsolutePath()); } catch (IOException e) { LOGGER.error(e); } }