List of usage examples for java.util.zip ZipOutputStream closeEntry
public void closeEntry() throws IOException
From source file:com.eviware.soapui.impl.wsdl.support.FileAttachment.java
public void setData(byte[] data) { try {/* ww w .j a v a 2s .co m*/ // write attachment-data to tempfile ByteArrayOutputStream tempData = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(tempData); out.putNextEntry(new ZipEntry(config.getName())); config.setSize(data.length); out.write(data); out.closeEntry(); out.finish(); out.close(); config.setData(tempData.toByteArray()); } catch (Exception e) { SoapUI.logError(e); } }
From source file:org.apache.felix.deploymentadmin.itest.util.DPSigner.java
public void writeSignedManifest(Manifest manifest, ZipOutputStream zos, PrivateKey privKey, X509Certificate cert) throws Exception { zos.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME)); manifest.write(zos);/*from w ww . j ava 2 s .com*/ zos.closeEntry(); long now = System.currentTimeMillis(); // Determine the signature-file manifest... Manifest sf = createSignatureFile(manifest); byte[] sfRawBytes; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { sf.write(baos); sfRawBytes = baos.toByteArray(); } ZipEntry sigFileEntry = new ZipEntry(m_baseName.concat(".SF")); sigFileEntry.setTime(now); zos.putNextEntry(sigFileEntry); // Write the actual entry data... zos.write(sfRawBytes, 0, sfRawBytes.length); zos.closeEntry(); // Create a PKCS#7 signature... byte[] encoded = calculateSignatureBlock(privKey, cert, sfRawBytes); ZipEntry blockFileEntry = new ZipEntry(m_baseName.concat(getBlockFileExtension(privKey))); blockFileEntry.setTime(now); zos.putNextEntry(blockFileEntry); zos.write(encoded); zos.closeEntry(); }
From source file:org.cloudfoundry.tools.io.zip.ZipArchiveTest.java
private InputStream createSampleZip() throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream); zipOutputStream.putNextEntry(new ZipEntry("a/")); zipOutputStream.closeEntry(); zipOutputStream.putNextEntry(new ZipEntry("a/b.txt")); IOUtils.write("ab", zipOutputStream); zipOutputStream.closeEntry();/* w ww . j av a 2s. c om*/ zipOutputStream.putNextEntry(new ZipEntry("c/")); zipOutputStream.closeEntry(); zipOutputStream.putNextEntry(new ZipEntry("c/d.txt")); IOUtils.write("cd", zipOutputStream); zipOutputStream.closeEntry(); zipOutputStream.close(); return new ByteArrayInputStream(outputStream.toByteArray()); }
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:org.codice.ddf.configuration.migration.MigrationZipFileTest.java
private void createZipWithEncryptedContents(Path zipPath, Path keyPath, Path checksumPath) throws Exception { Cipher cipher = createEncryptionCipher(keyPath); ZipEntry zipEntry = new ZipEntry("foo"); ZipEntry zipEntry1 = new ZipEntry("baz"); ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipPath.toFile())); zipOutputStream.putNextEntry(zipEntry); IOUtils.write("bar", new CipherOutputStream(zipOutputStream, cipher), StandardCharsets.UTF_8); zipOutputStream.closeEntry(); zipOutputStream.putNextEntry(zipEntry1); IOUtils.write("qux", new CipherOutputStream(zipOutputStream, cipher), StandardCharsets.UTF_8); zipOutputStream.closeEntry();/* w w w .j a v a2 s.c om*/ zipOutputStream.close(); createChecksum(zipPath, checksumPath); }
From source file:org.chromium.APKPackager.java
private void writeZipfile(File zipFile) throws IOException { if (zipFile.exists()) zipFile.delete();/*w ww . jav a 2s.c om*/ ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile)); ZipEntry e = new ZipEntry("dummydir"); out.putNextEntry(e); out.closeEntry(); out.close(); }
From source file:abfab3d.io.output.STSWriter.java
/** * Writes a grid out to an svx file// w w w.j a v a 2 s. c o m * @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(); } }
From source file:ZipTransformTest.java
public void testStreamTransformerIdentity() throws IOException { final String name = "foo"; final byte[] contents = "bar".getBytes(); File file1 = File.createTempFile("temp", null); File file2 = File.createTempFile("temp", null); try {/*ww w . j ava 2s.c o m*/ // Create the ZIP file ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1)); try { zos.putNextEntry(new ZipEntry(name)); zos.write(contents); zos.closeEntry(); } finally { IOUtils.closeQuietly(zos); } // Transform the ZIP file ZipUtil.transformEntry(file1, name, new StreamZipEntryTransformer() { protected void transform(ZipEntry zipEntry, InputStream in, OutputStream out) throws IOException { IOUtils.copy(in, out); } }, file2); // Test the ZipUtil byte[] actual = ZipUtil.unpackEntry(file2, name); assertNotNull(actual); assertEquals(new String(contents), new String(actual)); } finally { FileUtils.deleteQuietly(file1); FileUtils.deleteQuietly(file2); } }
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 www . j a va 2 s. com*/ @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:ZipTransformTest.java
public void testByteArrayTransformer() throws IOException { final String name = "foo"; final byte[] contents = "bar".getBytes(); File file1 = File.createTempFile("temp", null); File file2 = File.createTempFile("temp", null); try {// w w w . j a v a2 s. c o m // Create the ZIP file ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file1)); try { zos.putNextEntry(new ZipEntry(name)); zos.write(contents); zos.closeEntry(); } finally { IOUtils.closeQuietly(zos); } // Transform the ZIP file ZipUtil.transformEntry(file1, name, new ByteArrayZipEntryTransformer() { protected byte[] transform(ZipEntry zipEntry, byte[] input) throws IOException { String s = new String(input); assertEquals(new String(contents), s); return s.toUpperCase().getBytes(); } }, file2); // Test the ZipUtil byte[] actual = ZipUtil.unpackEntry(file2, name); assertNotNull(actual); assertEquals(new String(contents).toUpperCase(), new String(actual)); } finally { FileUtils.deleteQuietly(file1); FileUtils.deleteQuietly(file2); } }