List of usage examples for java.util.zip ZipOutputStream putNextEntry
public void putNextEntry(ZipEntry e) throws IOException
From source file:be.fedict.eid.applet.service.signer.ooxml.AbstractOOXMLSignatureService.java
private void addOriginSigs(ZipOutputStream zipOutputStream) throws IOException { zipOutputStream.putNextEntry(new ZipEntry("_xmlsignatures/origin.sigs")); }
From source file:com.googlecode.dex2jar.v3.DexExceptionHandlerImpl.java
public void dumpException(DexFileReader reader, File errorFile) throws IOException { for (Map.Entry<Method, Exception> e : exceptions.entrySet()) { System.err.println("Error:" + e.getKey().toString() + "->" + e.getValue().getMessage()); }/* w ww.ja v a2 s . co m*/ final ZipOutputStream errorZipOutputStream = new ZipOutputStream(FileUtils.openOutputStream(errorFile)); errorZipOutputStream.putNextEntry(new ZipEntry("summary.txt")); final PrintWriter fw = new PrintWriter(new OutputStreamWriter(errorZipOutputStream, "UTF-8")); fw.println(getVersionString()); fw.println("there are " + exceptions.size() + " error methods"); fw.print("options: "); if ((readerConfig & DexFileReader.SKIP_DEBUG) == 0) { fw.print(" -d"); } fw.println(); fw.flush(); errorZipOutputStream.closeEntry(); final Out out = new Out() { @Override public void pop() { } @Override public void push() { } @Override public void s(String s) { fw.println(s); } @Override public void s(String format, Object... arg) { fw.println(String.format(format, arg)); } }; final int[] count = new int[] { 0 }; reader.accept(new EmptyVisitor() { @Override public DexClassVisitor visit(int accessFlags, String className, String superClass, String[] interfaceNames) { return new EmptyVisitor() { @Override public DexMethodVisitor visitMethod(final int accessFlags, final Method method) { if (exceptions.containsKey(method)) { return new EmptyVisitor() { @Override public DexCodeVisitor visitCode() { try { errorZipOutputStream.putNextEntry(new ZipEntry("t" + count[0]++ + ".txt")); } catch (IOException e) { throw new RuntimeException(e); } Exception exception = exceptions.get(method); exception.printStackTrace(fw); out.s(""); out.s("DexMethodVisitor mv=cv.visitMethod(%s, %s);", Escape.methodAcc(accessFlags), Escape.v(method)); out.s("DexCodeVisitor code = mv.visitCode();"); return new ASMifierCodeV(out); } @Override public void visitEnd() { out.s("mv.visitEnd();"); fw.flush(); try { errorZipOutputStream.closeEntry(); } catch (IOException e) { throw new RuntimeException(e); } } }; } return null; } }; } }, readerConfig); errorZipOutputStream.close(); }
From source file:ch.silviowangler.dox.export.DoxExporterImpl.java
private void writeToZipOutputStream(ZipOutputStream out, byte[] dataBytes, String path) throws IOException { logger.trace("Writing to ZIP output stream using path '{}' and data length '{}'", path, dataBytes.length); out.putNextEntry(new ZipEntry(path)); out.write(dataBytes, 0, dataBytes.length); out.closeEntry(); // end of entry }
From source file:fr.cirad.mgdb.exporting.markeroriented.BEDExportHandler.java
@Override public void exportData(OutputStream outputStream, String sModule, List<SampleId> sampleIDs, ProgressIndicator progress, DBCursor markerCursor, Map<Comparable, Comparable> markerSynonyms, int nMinimumGenotypeQuality, int nMinimumReadDepth, Map<String, InputStream> readyToExportFiles) throws Exception { MongoTemplate mongoTemplate = MongoTemplateManager.get(sModule); ZipOutputStream zos = new ZipOutputStream(outputStream); if (readyToExportFiles != null) for (String readyToExportFile : readyToExportFiles.keySet()) { zos.putNextEntry(new ZipEntry(readyToExportFile)); InputStream inputStream = readyToExportFiles.get(readyToExportFile); byte[] dataBlock = new byte[1024]; int count = inputStream.read(dataBlock, 0, 1024); while (count != -1) { zos.write(dataBlock, 0, count); count = inputStream.read(dataBlock, 0, 1024); }//ww w . jav a 2 s. c o m } int markerCount = markerCursor.count(); List<String> selectedIndividualList = new ArrayList<String>(); for (Individual ind : getIndividualsFromSamples(sModule, sampleIDs)) selectedIndividualList.add(ind.getId()); String exportName = sModule + "_" + markerCount + "variants_" + selectedIndividualList.size() + "individuals"; zos.putNextEntry(new ZipEntry(exportName + ".bed")); short nProgress = 0, nPreviousProgress = 0; int nChunkSize = Math.min(2000, markerCount), nLoadedMarkerCount = 0; while (markerCursor.hasNext()) { int nLoadedMarkerCountInLoop = 0; Map<Comparable, String> markerChromosomalPositions = new LinkedHashMap<Comparable, String>(); boolean fStartingNewChunk = true; markerCursor.batchSize(nChunkSize); while (markerCursor.hasNext() && (fStartingNewChunk || nLoadedMarkerCountInLoop % nChunkSize != 0)) { DBObject exportVariant = markerCursor.next(); DBObject refPos = (DBObject) exportVariant.get(VariantData.FIELDNAME_REFERENCE_POSITION); markerChromosomalPositions.put((Comparable) exportVariant.get("_id"), refPos.get(ReferencePosition.FIELDNAME_SEQUENCE) + ":" + refPos.get(ReferencePosition.FIELDNAME_START_SITE)); nLoadedMarkerCountInLoop++; fStartingNewChunk = false; } for (Comparable variantId : markerChromosomalPositions.keySet()) // read data and write results into temporary files (one per sample) { String[] chromAndPos = markerChromosomalPositions.get(variantId).split(":"); zos.write((chromAndPos[0] + "\t" + (Long.parseLong(chromAndPos[1]) - 1) + "\t" + (Long.parseLong(chromAndPos[1]) - 1) + "\t" + variantId + "\t" + "0" + "\t" + "+") .getBytes()); zos.write((LINE_SEPARATOR).getBytes()); } if (progress.hasAborted()) return; nLoadedMarkerCount += nLoadedMarkerCountInLoop; nProgress = (short) (nLoadedMarkerCount * 100 / markerCount); if (nProgress > nPreviousProgress) { progress.setCurrentStepProgress(nProgress); nPreviousProgress = nProgress; } } zos.close(); progress.setCurrentStepProgress((short) 100); }
From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCache.java
private void addAsicContainersToArchive(ZipOutputStream zipOut) throws IOException { for (String eachName : archiveFileNames) { ZipEntry entry = new ZipEntry(eachName); zipOut.putNextEntry(entry); try (InputStream archiveInput = Files.newInputStream(createTempAsicPath(eachName))) { IOUtils.copy(archiveInput, zipOut); }/*from w w w .j a v a2 s . c om*/ zipOut.closeEntry(); } }
From source file:io.sledge.core.impl.installer.SledgePackageConfigurer.java
private void addToZipFile(String zipEntryName, InputStream inStream, ZipOutputStream zipStream) throws IOException { log.debug("Adding zip entry: " + zipEntryName); ZipEntry entry = new ZipEntry(zipEntryName); zipStream.putNextEntry(entry); byte[] readBuffer = new byte[2048]; int amountRead; int written = 0; while ((amountRead = inStream.read(readBuffer)) > 0) { zipStream.write(readBuffer, 0, amountRead); written += amountRead;// w w w .j a v a2 s. co m } zipStream.closeEntry(); log.debug("Written " + written + " bytes for: " + zipEntryName); }
From source file:com.headwire.aem.tooling.intellij.eclipse.stub.JarBuilder.java
private void zipDir(final IFolder sourceDir, final ZipOutputStream zos, final String path) throws CoreException, IOException { for (final IResource f : sourceDir.members()) { if (f.getType() == IResource.FOLDER) { final String prefix = path + f.getName() + "/"; zos.putNextEntry(new ZipEntry(prefix)); zipDir((IFolder) f, zos, prefix); } else if (f.getType() == IResource.FILE) { final String entry = path + f.getName(); if (JarFile.MANIFEST_NAME.equals(entry)) { continue; }/* w ww. j a va2 s . co m*/ final InputStream fis = ((IFile) f).getContents(); try { final byte[] readBuffer = new byte[8192]; int bytesIn = 0; final ZipEntry anEntry = new ZipEntry(entry); zos.putNextEntry(anEntry); while ((bytesIn = fis.read(readBuffer)) != -1) { zos.write(readBuffer, 0, bytesIn); } } finally { IOUtils.closeQuietly(fis); } } } }
From source file:com.datasalt.pangool.solr.SolrRecordWriter.java
/** * Write a file to a zip output stream, removing leading path name components from the actual file name when creating * the zip file entry.//www. j ava2 s . c o m * * The entry placed in the zip file is <code>baseName</code>/ <code>relativePath</code>, where * <code>relativePath</code> is constructed by removing a leading <code>root</code> from the path for * <code>itemToZip</code>. * * If <code>itemToZip</code> is an empty directory, it is ignored. If <code>itemToZip</code> is a directory, the * contents of the directory are added recursively. * * @param zos * The zip output stream * @param baseName * The base name to use for the file name entry in the zip file * @param root * The path to remove from <code>itemToZip</code> to make a relative path name * @param itemToZip * The path to the file to be added to the zip file * @return the number of entries added * @throws IOException */ static public int zipDirectory(final Configuration conf, final ZipOutputStream zos, final String baseName, final String root, final Path itemToZip) throws IOException { LOG.info(String.format("zipDirectory: %s %s %s", baseName, root, itemToZip)); LocalFileSystem localFs = FileSystem.getLocal(conf); int count = 0; final FileStatus itemStatus = localFs.getFileStatus(itemToZip); if (itemStatus.isDir()) { final FileStatus[] statai = localFs.listStatus(itemToZip); // Add a directory entry to the zip file final String zipDirName = relativePathForZipEntry(itemToZip.toUri().getPath(), baseName, root); final ZipEntry dirZipEntry = new ZipEntry(zipDirName + Path.SEPARATOR_CHAR); LOG.info(String.format("Adding directory %s to zip", zipDirName)); zos.putNextEntry(dirZipEntry); zos.closeEntry(); count++; if (statai == null || statai.length == 0) { LOG.info(String.format("Skipping empty directory %s", itemToZip)); return count; } for (FileStatus status : statai) { count += zipDirectory(conf, zos, baseName, root, status.getPath()); } LOG.info(String.format("Wrote %d entries for directory %s", count, itemToZip)); return count; } final String inZipPath = relativePathForZipEntry(itemToZip.toUri().getPath(), baseName, root); if (inZipPath.length() == 0) { LOG.warn(String.format("Skipping empty zip file path for %s (%s %s)", itemToZip, root, baseName)); return 0; } // Take empty files in case the place holder is needed FSDataInputStream in = null; try { in = localFs.open(itemToZip); final ZipEntry ze = new ZipEntry(inZipPath); ze.setTime(itemStatus.getModificationTime()); // Comments confuse looking at the zip file // ze.setComment(itemToZip.toString()); zos.putNextEntry(ze); IOUtils.copyBytes(in, zos, conf, false); zos.closeEntry(); LOG.info(String.format("Wrote %d entries for file %s", count, itemToZip)); return 1; } finally { in.close(); } }
From source file:com.healthcit.analytics.servlet.DataExportServlet.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String token = request.getParameter("token"); TOKENS_MAP.put(token, DownloadStatus.STARTED); String keys = request.getParameter("keys"); if (keys != null) { //JSONArray ownerIdsJSON = (JSONArray)JSONSerializer.toJSON(ownerIds ) ; String[] ownerIdsArray = StringUtils.split(keys, ","); response.setContentType(Constants.JSON_CONTENT_TYPE); response.addHeader(Constants.CONTENT_DISPOSITION, "attachment; filename=dataExport.zip"); response.addHeader(Constants.PRAGMA_HEADER, Constants.NO_CACHE); response.setHeader(Constants.CACHE_CONTROL_HEADER, Constants.NO_CACHE); ServletOutputStream os = response.getOutputStream(); ZipOutputStream zos = new ZipOutputStream(os); // ZipEntry entry = new ZipEntry("dataExport."+OutputFormat.JSON.toString().toLowerCase()); ZipEntry entry = new ZipEntry("dataExport." + OutputFormat.XML.toString().toLowerCase()); zos.putNextEntry(entry); // OwnerDataManager ownerManager = new OwnerDataManager(OutputFormat.JSON); OwnerDataManager ownerManager = new OwnerDataManager(OutputFormat.XML); try {//from w ww . j a va 2 s.c o m ownerManager.getEntitiesData(ownerIdsArray, zos); TOKENS_MAP.put(token, DownloadStatus.FINISHED); } catch (Exception e) { log.error(e.getMessage(), e); TOKENS_MAP.put(token, DownloadStatus.ERROR); } finally { zos.close(); // os.flush(); // os.close(); } } else { TOKENS_MAP.put(token, DownloadStatus.ERROR); } }
From source file:abfab3d.io.output.STSWriter.java
/** * Writes a grid out to an svx file//w w w .jav a 2 s .c om * @param grid * @param os */ public void write(AttributeGrid grid, MaterialMaker[] makers, String[] finish, ZipOutputStream os) { try { ZipEntry zentry = new ZipEntry("manifest.xml"); os.putNextEntry(zentry); writeManifest(grid, makers, finish, os); os.closeEntry(); double maxDecimationError = errorFactor * grid.getVoxelSize() * grid.getVoxelSize(); int len = makers.length; for (int i = 0; i < len; i++) { ZipEntry ze = new ZipEntry("part" + i + "." + format); ((ZipOutputStream) os).putNextEntry(ze); MeshMakerMT meshmaker = new MeshMakerMT(); meshmaker.setBlockSize(30); meshmaker.setThreadCount(threadCount); meshmaker.setSmoothingWidth(smoothingWidth); meshmaker.setMaxDecimationError(maxDecimationError); meshmaker.setMaxDecimationCount(10); meshmaker.setMaxAttributeValue(255); meshmaker.setDensityMaker(makers[i].getDensityMaker()); IndexedTriangleSetBuilder its = new IndexedTriangleSetBuilder(160000); meshmaker.makeMesh(grid, its); System.out.println("Vertices: " + its.getVertexCount() + " faces: " + its.getFaceCount()); WingedEdgeTriangleMesh mesh = new WingedEdgeTriangleMesh(its.getVertices(), its.getFaces()); if (minPartVolume > 0 || maxPartsCount < Integer.MAX_VALUE) { ShellResults sr = GridSaver.getLargestShells(mesh, maxPartsCount, minPartVolume); mesh = sr.getLargestShell(); int regions_removed = sr.getShellsRemoved(); System.out.println("Regions removed: " + regions_removed); } if (format.equals("x3d") || format.equals("x3dv") || format.equals("x3db")) { double[] bounds_min = new double[3]; double[] bounds_max = new double[3]; grid.getGridBounds(bounds_min, bounds_max); double max_axis = Math.max(bounds_max[0] - bounds_min[0], bounds_max[1] - bounds_min[1]); max_axis = Math.max(max_axis, bounds_max[2] - bounds_min[2]); double z = 2 * max_axis / Math.tan(Math.PI / 4); float[] pos = new float[] { 0, 0, (float) z }; BinaryContentHandler x3dWriter = createX3DWriter(os); HashMap<String, Object> x3dParams = new HashMap<String, Object>(); GridSaver.writeMesh(mesh, 10, x3dWriter, x3dParams, true); x3dWriter.endDocument(); } else if (format.equals("stl")) { STLWriter stl = new STLWriter(os, mesh.getTriangleCount()); mesh.getTriangles(stl); } ((ZipOutputStream) os).closeEntry(); } } catch (IOException ioe) { ioe.printStackTrace(); } }