List of usage examples for java.util.zip ZipOutputStream closeEntry
public void closeEntry() throws IOException
From source file:com.eviware.soapui.testondemand.TestOnDemandCaller.java
private static byte[] zipBytes(String filename, byte[] dataToBeZiped) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zipedOutputStream = new ZipOutputStream(outputStream); ZipEntry entry = new ZipEntry(filename); entry.setSize(dataToBeZiped.length); try {//ww w. ja va 2s .c o m zipedOutputStream.putNextEntry(entry); zipedOutputStream.write(dataToBeZiped); } finally { zipedOutputStream.closeEntry(); zipedOutputStream.close(); } return outputStream.toByteArray(); }
From source file:de.tor.tribes.util.AttackToTextWriter.java
private static boolean writeBlocksToZip(List<String> pBlocks, Tribe pTribe, File pPath) { int fileNo = 1; String baseFilename = pTribe.getName().replaceAll("\\W+", ""); ZipOutputStream zout = null; try {/*from w w w. j a v a2 s.co m*/ zout = new ZipOutputStream( new FileOutputStream(FilenameUtils.concat(pPath.getPath(), baseFilename + ".zip"))); for (String block : pBlocks) { String entryName = baseFilename + fileNo + ".txt"; ZipEntry entry = new ZipEntry(entryName); try { zout.putNextEntry(entry); zout.write(block.getBytes()); zout.closeEntry(); } catch (IOException ioe) { logger.error("Failed to write attack to zipfile", ioe); return false; } fileNo++; } } catch (IOException ioe) { logger.error("Failed to write content to zip file", ioe); return false; } finally { if (zout != null) { try { zout.flush(); zout.close(); } catch (IOException ignored) { } } } return true; }
From source file:Main.java
static void addDir(File dirObj, ZipOutputStream out) throws IOException { File[] files = dirObj.listFiles(); byte[] tmpBuf = new byte[1024]; for (int i = 0; i < files.length; i++) { if (files[i].isDirectory()) { addDir(files[i], out);/*from w w w .j a v a 2s . c o m*/ continue; } FileInputStream in = new FileInputStream(files[i].getAbsolutePath()); System.out.println(" Adding: " + files[i].getAbsolutePath()); out.putNextEntry(new ZipEntry(files[i].getAbsolutePath())); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } out.closeEntry(); in.close(); } }
From source file:Main.java
public static void zipMutiCompress(File[] srcfile, File destFile) { byte[] buf = new byte[BUFFERED_SIZE]; try {// www . jav a2 s . c om ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destFile)); if (null != srcfile && srcfile.length > 0) { for (int i = 0; i < srcfile.length; i++) { File file = srcfile[i]; if (null != file) { FileInputStream in = new FileInputStream(file); out.putNextEntry(new ZipEntry(file.getName())); int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); in.close(); } } } out.close(); } catch (IOException e) { } }
From source file:com.nuvolect.securesuite.util.OmniZip.java
public static void zipFile(String basePath, OmniFile file, ZipOutputStream zout) throws IOException { LogUtil.log(LogUtil.LogType.OMNI_ZIP, "zipFile : " + file.getPath()); byte[] buffer = new byte[4096]; InputStream fin = file.getFileInputStream(); zout.putNextEntry(new ZipEntry(basePath + file.getName())); int length;/*from w w w .jav a 2 s .c om*/ while ((length = fin.read(buffer)) > 0) { zout.write(buffer, 0, length); } zout.closeEntry(); fin.close(); }
From source file:de.decidr.model.workflowmodel.deployment.PackageBuilder.java
/** * @param workFlowId/*from w w w. ja v a2s.c om*/ * @param bpel * @param wsdl * @param dd * depoyment descriptor * @param serverLocation * location for service endpoints * @return the zip'ed package as byte array * @throws JAXBException * @throws IOException */ public static byte[] getPackage(long workFlowId, TProcess bpel, TDefinitions wsdl, TDeployment dd, HashMap<String, List<ServerLoadView>> serverMap) throws JAXBException, IOException { ByteArrayOutputStream zipOut = new ByteArrayOutputStream(); TransformationHelper th = new TransformationHelper(); de.decidr.model.schema.bpel.executable.ObjectFactory of = new de.decidr.model.schema.bpel.executable.ObjectFactory(); de.decidr.model.schema.wsdl.ObjectFactory ofwasl = new de.decidr.model.schema.wsdl.ObjectFactory(); de.decidr.model.schema.bpel.dd.ObjectFactory ofdd = new de.decidr.model.schema.bpel.dd.ObjectFactory(); JAXBElement<TDefinitions> def = ofwasl.createDefinitions(wsdl); JAXBElement<TDeployment> d = ofdd.createDeploy(dd); String bpelFilename = "BPELPROCESS_" + workFlowId + ".bpel"; String wsdlFilename = TransformConstants.FILENAME_WSDL_PROCESS_NAME_TEMPLATE.replace("?", workFlowId + ""); String ddFilename = "deploy.xml"; ZipOutputStream zip_out_stream = new ZipOutputStream(zipOut); // Add BPEL to zip zip_out_stream.putNextEntry(new ZipEntry(bpelFilename)); String fileBPEL = th.jaxbObjectToStringWithWorkflowNamespace(of.createProcess(bpel), bpel.getTargetNamespace(), TransformationHelper.BPEL_CLASSES); zip_out_stream.write(fileBPEL.getBytes()); zip_out_stream.closeEntry(); // Add WSDL to zip zip_out_stream.putNextEntry(new ZipEntry(wsdlFilename)); String fileWSDL = th.jaxbObjectToStringWithWorkflowNamespace(def, bpel.getTargetNamespace(), TransformationHelper.WSDL_CLASSES); zip_out_stream.write(fileWSDL.getBytes()); zip_out_stream.closeEntry(); // Add Deployment Descriptor to zip zip_out_stream.putNextEntry(new ZipEntry(ddFilename)); String fileDD = th.jaxbObjectToStringWithWorkflowNamespace(d, bpel.getTargetNamespace(), TransformationHelper.DD_CLASSES); zip_out_stream.write(fileDD.getBytes()); zip_out_stream.closeEntry(); // Add the EMail WSDL to package and modify the service endpoint zip_out_stream.putNextEntry(new ZipEntry(TransformConstants.FILENAME_WSDL_EMAIL)); zip_out_stream.write(getEmailWsdl( URLGenerator.getEmailWSUrl(serverMap.get(ServerTypeEnum.Ode.toString()).get(0).getLocation()))); zip_out_stream.closeEntry(); // Add the HT WSDL to package and modify the service endpoint zip_out_stream.putNextEntry(new ZipEntry(TransformConstants.FILENAME_WSDL_HUMANTASK)); zip_out_stream.write(getHTWsdl( URLGenerator.getHumanTaskWSUrl(serverMap.get(ServerTypeEnum.Ode.toString()).get(0).getLocation()))); zip_out_stream.closeEntry(); // Add the PS WSDL to package and modify the service endpoint zip_out_stream.putNextEntry(new ZipEntry(TransformConstants.FILENAME_WSDL_PROXY)); zip_out_stream.write(getPSWsdl(URLGenerator .getProxyServiceWSUrl(serverMap.get(ServerTypeEnum.Ode.toString()).get(0).getLocation()))); zip_out_stream.closeEntry(); // Add DecidrTypes schema to package zip_out_stream.putNextEntry(new ZipEntry(TransformConstants.FILENAME_XSD_DECIDR_TYPES)); zip_out_stream.write(loadSchema(TransformConstants.FILENAME_XSD_DECIDR_TYPES)); zip_out_stream.closeEntry(); zip_out_stream.close(); return zipOut.toByteArray(); }
From source file:Utils.java
/** * Zip a list of file into one zip file. * // w w w. ja v a 2 s .c o m * @param files * files to zip * @param targetZipFile * target zip file * @throws IOException * IO error exception can be thrown when copying ... */ public static void zipFile(final File[] files, final File targetZipFile) throws IOException { try { FileOutputStream fos = new FileOutputStream(targetZipFile); ZipOutputStream zos = new ZipOutputStream(fos); byte[] buffer = new byte[128]; for (int i = 0; i < files.length; i++) { File currentFile = files[i]; if (!currentFile.isDirectory()) { ZipEntry entry = new ZipEntry(currentFile.getName()); FileInputStream fis = new FileInputStream(currentFile); zos.putNextEntry(entry); int read = 0; while ((read = fis.read(buffer)) != -1) { zos.write(buffer, 0, read); } zos.closeEntry(); fis.close(); } } zos.close(); fos.close(); } catch (FileNotFoundException e) { System.out.println("File not found : " + e); } }
From source file:cc.recommenders.utils.Zips.java
public static void zip(File directory, File out) throws IOException { ZipOutputStream zos = null; try {/* w w w. j a v a 2 s .c om*/ OutputSupplier<FileOutputStream> s = Files.newOutputStreamSupplier(out); zos = new ZipOutputStream(s.getOutput()); Collection<File> files = FileUtils.listFiles(directory, FILE, DIRECTORY); for (File f : files) { String path = removeStart(f.getPath(), directory.getAbsolutePath() + "/"); ZipEntry e = new ZipEntry(path); zos.putNextEntry(e); byte[] data = Files.toByteArray(f); zos.write(data); zos.closeEntry(); } } finally { Closeables.close(zos, false); } }
From source file:de.thischwa.pmcms.tool.compression.Zip.java
/** * Static method to compress all files based on the ImputStream in 'entries' into 'zip'. * Each entry has a InputStream and its String representation in the zip. * //from www . j a v a 2 s. c om * @param zip The zip file. It will be deleted if exists. * @param entries Map<File, String> * @param monitor Must be initialized correctly by the caller. * @throws IOException */ public static void compress(final File zip, final Map<InputStream, String> entries, final IProgressMonitor monitor) throws IOException { if (zip == null || entries == null || CollectionUtils.isEmpty(entries.keySet())) throw new IllegalArgumentException("One ore more parameters are empty!"); if (zip.exists()) zip.delete(); else if (!zip.getParentFile().exists()) zip.getParentFile().mkdirs(); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zip))); out.setLevel(Deflater.BEST_COMPRESSION); try { for (InputStream inputStream : entries.keySet()) { // skip beginning slash, because can cause errors in other zip apps ZipEntry zipEntry = new ZipEntry(skipBeginningSlash(entries.get(inputStream))); out.putNextEntry(zipEntry); IOUtils.copy(inputStream, out); out.closeEntry(); inputStream.close(); if (monitor != null) monitor.worked(1); } } finally { // cleanup IOUtils.closeQuietly(out); } }
From source file:Main.java
public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception { File tmpFile = File.createTempFile("z4zip-tmp-", ".zip"); tmpFile.deleteOnExit();/*from w w w.j a v a2 s . c om*/ ZipFile inZip = new ZipFile(sZipFile); ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath())); Enumeration<? extends ZipEntry> entries = inZip.entries(); while (entries.hasMoreElements()) { ZipEntry e = entries.nextElement(); outZip.putNextEntry(e); if (!e.isDirectory()) { File f = new File(sPath + "/" + e.getName()); if (f.exists()) { copy(new FileInputStream(f.getPath()), outZip); } else { copy(inZip.getInputStream(e), outZip); } } outZip.closeEntry(); } inZip.close(); outZip.close(); return tmpFile; }