List of usage examples for java.util.zip ZipOutputStream closeEntry
public void closeEntry() throws IOException
From source file:org.akvo.flow.service.DataSyncService.java
/** * writes the contents of text to a zip entry within the Zip file behind zos * named fileName/* www . j a v a 2 s . c o m*/ * * @param zos * @param text * @param fileName * @throws java.io.IOException */ private void writeTextToZip(ZipOutputStream zos, String text, String fileName) throws IOException { Log.i(TAG, "Writing zip entry"); zos.putNextEntry(new ZipEntry(fileName)); byte[] allBytes = text.getBytes("UTF-8"); zos.write(allBytes, 0, allBytes.length); zos.closeEntry(); Log.i(TAG, "Entry Complete"); }
From source file:com.wavemaker.tools.project.StageDeploymentManager.java
protected void assembleEar(Map<String, Object> properties, com.wavemaker.tools.io.File warFile) { ZipOutputStream out; InputStream is;/* ww w . j a v a 2s . c o m*/ try { com.wavemaker.tools.io.File earFile = (com.wavemaker.tools.io.File) properties .get(EAR_FILE_NAME_PROPERTY); out = new ZipOutputStream(earFile.getContent().asOutputStream()); out.putNextEntry(new ZipEntry(warFile.getName())); is = warFile.getContent().asInputStream(); org.apache.commons.io.IOUtils.copy(is, out); out.closeEntry(); is.close(); Folder webInf = ((Folder) properties.get(BUILD_WEBAPPROOT_PROPERTY)).getFolder("WEB-INF"); com.wavemaker.tools.io.File appXml = webInf.getFile("application.xml"); out.putNextEntry(new ZipEntry("META-INF/" + appXml.getName())); is = appXml.getContent().asInputStream(); org.apache.commons.io.IOUtils.copy(is, out); out.closeEntry(); is.close(); String maniFest = "Manifest-Version: 1.0\n" + "Created-By: WaveMaker Studio (CloudJee Inc.)"; out.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF")); org.apache.commons.io.IOUtils.write(maniFest, out); out.closeEntry(); is.close(); out.close(); } catch (IOException ex) { throw new WMRuntimeException(ex); } }
From source file:com.googlecode.clearnlp.component.AbstractStatisticalComponent.java
/** Called by {@link AbstractStatisticalComponent#saveModels(ZipOutputStream)}}. */ protected void saveFeatureTemplates(ZipOutputStream zout, String entryName) throws Exception { int i, size = f_xmls.length; PrintStream fout;/* w ww.ja v a 2 s.c o m*/ LOG.info("Saving feature templates.\n"); for (i = 0; i < size; i++) { zout.putNextEntry(new ZipEntry(entryName + i)); fout = UTOutput.createPrintBufferedStream(zout); IOUtils.copy(UTInput.toInputStream(f_xmls[i].toString()), fout); fout.flush(); zout.closeEntry(); } }
From source file:com.juancarlosroot.threads.SimulatedUser.java
private String firmarImagen(int fileName) throws IOException { String result = ""; try {//from w w w . j ava 2 s . c om Path currentRelativePath = Paths.get(""); String s = currentRelativePath.toAbsolutePath().toString(); String theFolder = s + "/" + "archivos"; FileOutputStream fos = new FileOutputStream(userFolderPath + "/" + Integer.toString(fileName) + ".zip"); ZipOutputStream zos = new ZipOutputStream(fos); String file1Name = theFolder + "/" + Integer.toString(fileName) + ".jpg"; File image = new File(file1Name); ZipEntry zipEntry = new ZipEntry(image.getName()); zos.putNextEntry(zipEntry); FileInputStream fileInputStream = new FileInputStream(image); byte[] buf = new byte[2048]; int bytesRead; while ((bytesRead = fileInputStream.read(buf)) > 0) { zos.write(buf, 0, bytesRead); } zos.closeEntry(); zos.close(); fos.close(); Path path = Paths.get(userFolderPath + "/" + Integer.toString(fileName) + ".zip"); byte[] data = Files.readAllBytes(path); byte[] byteArray = Base64.encodeBase64(data); String b64 = new String(byteArray); result = firma(b64, Integer.toString(fileName), "pruebita"); System.out.println("User : " + idSimulatedUser + " ENVIADO"); nFilesSend++; } catch (FileNotFoundException ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); } catch (WriterException_Exception ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException_Exception ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException_Exception ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); } catch (InterruptedException_Exception ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); } return "http://" + result; }
From source file:com.juancarlosroot.threads.SimulatedUser.java
private void consultarFirma(int fileNameId) { try {//w w w . ja v a 2 s. c o m FileOutputStream fos = new FileOutputStream( userFolderPath + "/" + Integer.toString(fileNameId) + "Firmada.zip"); ZipOutputStream zos = new ZipOutputStream(fos); String file1Name = userFolderPath + "/" + Integer.toString(fileNameId) + "Firmada.png"; File image = new File(file1Name); ZipEntry zipEntry = new ZipEntry(image.getName()); zos.putNextEntry(zipEntry); FileInputStream fileInputStream = new FileInputStream(image); byte[] buf = new byte[2048]; int bytesRead; while ((bytesRead = fileInputStream.read(buf)) > 0) { zos.write(buf, 0, bytesRead); } zos.closeEntry(); zos.close(); fos.close(); Path path = Paths.get(userFolderPath + "/" + Integer.toString(fileNameId) + "Firmada.zip"); byte[] data = Files.readAllBytes(path); byte[] byteArray = Base64.encodeBase64(data); String b64 = new String(byteArray); System.out.println(consultaFirma(b64, Integer.toString(fileNameId) + "Firmada")); nFilesVerified++; System.out.println("User : " + idSimulatedUser + " FIRMA VERIFICADA"); } catch (IOException ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); nNotFileFound++; } catch (IOException_Exception ex) { Logger.getLogger(SimulatedUser.class.getName()).log(Level.SEVERE, null, ex); nVerifyErrors++; } }
From source file:eu.planets_project.pp.plato.action.ProjectExportAction.java
/** * Exports all projects into separate xml files and adds them to a zip archive. * @return null Always returns null, so user stays on same screen after action performed *//* www . ja v a2 s.co m*/ public String exportAllProjectsToZip() { List<PlanProperties> ppList = em.createQuery("select p from PlanProperties p").getResultList(); if (!ppList.isEmpty()) { log.debug("number of plans to export: " + ppList.size()); String filename = "allprojects.zip"; String exportPath = OS.getTmpPath() + "export" + System.currentTimeMillis() + "/"; new File(exportPath).mkdirs(); String binarydataTempPath = exportPath + "binarydata/"; File binarydataTempDir = new File(binarydataTempPath); binarydataTempDir.mkdirs(); try { OutputStream out = new BufferedOutputStream(new FileOutputStream(exportPath + filename)); ZipOutputStream zipOut = new ZipOutputStream(out); for (PlanProperties pp : ppList) { log.debug("EXPORTING: " + pp.getName()); ZipEntry zipAdd = new ZipEntry(String.format("%1$03d", pp.getId()) + "-" + FileUtils.makeFilename(pp.getName()) + ".xml"); zipOut.putNextEntry(zipAdd); // export the complete project, including binary data exportComplete(pp.getId(), zipOut, binarydataTempPath); zipOut.closeEntry(); } zipOut.close(); out.close(); new File(exportPath + "finished.info").createNewFile(); FacesMessages.instance().add(FacesMessage.SEVERITY_INFO, "Export was written to: " + exportPath); log.info("Export was written to: " + exportPath); } catch (IOException e) { FacesMessages.instance().add(FacesMessage.SEVERITY_ERROR, "An error occured while generating the export file."); log.error("An error occured while generating the export file.", e); File errorInfo = new File(exportPath + "error.info"); try { Writer w = new FileWriter(errorInfo); w.write("An error occured while generating the export file:"); w.write(e.getMessage()); w.close(); } catch (IOException e1) { log.error("Could not write error file."); } } finally { // remove all binary temp files OS.deleteDirectory(binarydataTempDir); } } else { FacesMessages.instance().add("No Projects found!"); } return null; }
From source file:au.org.ala.layers.web.UserDataService.java
@RequestMapping(value = WS_USERDATA_SAMPLE, method = { RequestMethod.POST, RequestMethod.GET }) public @ResponseBody void samplezip(HttpServletRequest req, HttpServletResponse resp) { RecordsLookup.setUserDataDao(userDataDao); String id = req.getParameter("q"); String fields = req.getParameter("fl"); String sample = userDataDao.getSampleZip(id, fields); try {//from ww w . j a v a 2 s.co m // Create the ZIP file ZipOutputStream out = new ZipOutputStream(resp.getOutputStream()); //put entry out.putNextEntry(new ZipEntry("sample.csv")); out.write(sample.getBytes()); out.closeEntry(); resp.setContentType("application/zip"); resp.setHeader("Content-Disposition", "attachment; filename=\"sample.zip\""); // Complete the ZIP file out.close(); } catch (Exception e) { logger.error("failed to zip sampling", e); } }
From source file:com.webpagebytes.cms.controllers.FlatStorageImporterExporter.java
protected void exportUris(ZipOutputStream zos, String path) throws WPBIOException { try {// w w w . j av a2 s . c o m List<WPBUri> uris = dataStorage.getAllRecords(WPBUri.class); ZipEntry zeExternalGuid = new ZipEntry(path); zos.putNextEntry(zeExternalGuid); zos.closeEntry(); for (WPBUri uri : uris) { String guidPath = PATH_URIS + uri.getExternalKey() + "/"; Map<String, Object> map = new HashMap<String, Object>(); exporter.export(uri, map); String metadataXml = guidPath + "metadata.xml"; ZipEntry metadataZe = new ZipEntry(metadataXml); zos.putNextEntry(metadataZe); exportToXMLFormat(map, zos); zos.closeEntry(); String parametersPath = String.format(PATH_URI_PARAMETERS, uri.getExternalKey()); ZipEntry paramsZe = new ZipEntry(parametersPath); zos.putNextEntry(paramsZe); zos.closeEntry(); exportParameters(uri.getExternalKey(), zos, parametersPath); } } catch (IOException e) { log.log(Level.SEVERE, e.getMessage(), e); throw new WPBIOException("Cannot export uri's to Zip", e); } }
From source file:ZipImploder.java
/** * process a single file for a .zip file * // ww w . ja v a2 s.c o m * @param zos * @param f * @throws IOException */ public void processFile(ZipOutputStream zos, File f) throws IOException { String path = f.getCanonicalPath(); path = path.replace('\\', '/'); String xpath = removeDrive(removeLead(path)); ZipEntry ze = new ZipEntry(xpath); ze.setTime(f.lastModified()); ze.setSize(f.length()); zos.putNextEntry(ze); fileCount++; try { copyFileEntry(zos, f); } finally { zos.closeEntry(); } }
From source file:nl.b3p.viewer.features.ShapeDownloader.java
/** * This method zips the directory/* w ww . java2s.c om*/ * * @param dir * @param zipDirName */ private void zipDirectory(File dir, File zip) throws IOException { try { List<String> filesListInDir = new ArrayList<String>(); populateFilesList(dir, filesListInDir); //now zip files one by one //create ZipOutputStream to write to the zip file FileOutputStream fos = new FileOutputStream(zip); ZipOutputStream zos = new ZipOutputStream(fos); for (String filePath : filesListInDir) { //for ZipEntry we need to keep only relative file path, so we used substring on absolute path ZipEntry ze = new ZipEntry( filePath.substring(dir.getAbsolutePath().length() + 1, filePath.length())); zos.putNextEntry(ze); //read the file and write to ZipOutputStream FileInputStream fis = new FileInputStream(filePath); byte[] buffer = new byte[1024]; int len; while ((len = fis.read(buffer)) > 0) { zos.write(buffer, 0, len); } zos.closeEntry(); fis.close(); } zos.close(); fos.close(); } catch (IOException e) { log.error("Could not write zipfile. Exiting.", e); throw e; } }