List of usage examples for java.util.zip ZipOutputStream closeEntry
public void closeEntry() throws IOException
From source file:nl.coinsweb.sdk.FileManager.java
private static void addFileToZip(String fromPath, Path zipPath, ZipOutputStream zos) { // Do dark magic, needed to correct ikvm consequences String pathInZip = zipPath.toFile().getPath().replace("\\", "/"); try {// w w w . ja v a 2 s.c o m final byte[] buffer = new byte[1024]; ZipEntry ze = new ZipEntry(pathInZip); zos.putNextEntry(ze); log.trace("Adding to zip: " + pathInZip); // Write file content FileInputStream in = new FileInputStream(fromPath); int len; while ((len = in.read(buffer)) != -1) { zos.write(buffer, 0, len); } zos.closeEntry(); in.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.yunmel.syncretic.utils.io.IOUtils.java
/** * ZIP?/*from ww w . j a v a 2 s . com*/ * * @param dirPath * @param fileDir ? * @param zouts ? */ public static void zipDirectoryToZipFile(String dirPath, File fileDir, ZipOutputStream zouts) { if (fileDir.isDirectory()) { File[] files = fileDir.listFiles(); // if (files.length == 0) { // ? ZipEntry entry = new ZipEntry(getEntryName(dirPath, fileDir)); try { zouts.putNextEntry(entry); zouts.closeEntry(); } catch (Exception e) { e.printStackTrace(); } return; } for (int i = 0; i < files.length; i++) { if (files[i].isFile()) { // IOUtils.zipFilesToZipFile(dirPath, files[i], zouts); } else { // IOUtils.zipDirectoryToZipFile(dirPath, files[i], zouts); } } } }
From source file:org.agnitas.util.ZipUtilities.java
/** * Add data to an open ZipOutputStream as a virtual file * /*from w ww. j a va2 s . c o m*/ * @param fileData * @param relativeDirPath * @param filename * @param destinationZipFileSream * @throws IOException */ public static void addFileDataToOpenZipFileStream(byte[] fileData, String relativeDirPath, String filename, ZipOutputStream destinationZipFileSream) throws IOException { if (fileData == null) throw new IOException("FileData is missing"); if (StringUtils.isEmpty(filename) || filename.trim().length() == 0) throw new IOException("Filename is missing"); if (destinationZipFileSream == null) throw new IOException("DestinationStream is not ready"); if (relativeDirPath == null || (!relativeDirPath.endsWith("/") && !relativeDirPath.endsWith("\\"))) throw new IOException("RelativeDirPath is invalid"); ZipEntry entry = new ZipEntry(relativeDirPath + filename); entry.setTime(new Date().getTime()); destinationZipFileSream.putNextEntry(entry); destinationZipFileSream.write(fileData); destinationZipFileSream.flush(); destinationZipFileSream.closeEntry(); }
From source file:abfab3d.io.output.SVXWriter.java
/** * Writes a grid out to an svx file/*from w w w. jav a 2s .c om*/ * @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:b2s.idea.mavenize.JarCombiner.java
private void addServiceEntries(ZipOutputStream zipOut, JarContext context) throws IOException { for (Map.Entry<String, StringBuilder> entry : context.getServices()) { zipOut.putNextEntry(new ZipEntry(entry.getKey())); zipOut.write(entry.getValue().toString().getBytes()); zipOut.closeEntry(); }/*from ww w. ja va2 s . c om*/ }
From source file:eionet.gdem.utils.ZipUtil.java
/** * * @param f/* w w w . jav a 2 s. c om*/ * - File that will be zipped * @param outZip * - ZipOutputStream represents the zip file, where the files will be placed * @param sourceDir * - root directory, where the zipping started * @param doCompress * - don't comress the file, if doCompress=true * @throws IOException If an error occurs. */ public static void zipFile(File f, ZipOutputStream outZip, String sourceDir, boolean doCompress) throws IOException { // Read the source file into byte array byte[] fileBytes = Utils.getBytesFromFile(f); // create a new zip entry String strAbsPath = f.getPath(); String strZipEntryName = strAbsPath.substring(sourceDir.length() + 1, strAbsPath.length()); strZipEntryName = Utils.Replace(strZipEntryName, File.separator, "/"); ZipEntry anEntry = new ZipEntry(strZipEntryName); // Don't compress the file, if not needed if (!doCompress) { // ZipEntry can't calculate crc size automatically, if we use STORED method. anEntry.setMethod(ZipEntry.STORED); anEntry.setSize(fileBytes.length); CRC32 crc321 = new CRC32(); crc321.update(fileBytes); anEntry.setCrc(crc321.getValue()); } // place the zip entry in the ZipOutputStream object outZip.putNextEntry(anEntry); // now write the content of the file to the ZipOutputStream outZip.write(fileBytes); outZip.flush(); // Close the current entry outZip.closeEntry(); }
From source file:org.fenixedu.start.controller.StartController.java
private ResponseEntity<byte[]> build(Map<String, byte[]> project, ProjectRequest request) throws IOException { ByteArrayOutputStream stream = new ByteArrayOutputStream(); ZipOutputStream zip = new ZipOutputStream(stream); for (Map.Entry<String, byte[]> mapEntry : project.entrySet()) { ZipEntry entry = new ZipEntry(request.getArtifactId() + "/" + mapEntry.getKey()); zip.putNextEntry(entry);/* w w w. j a va2 s.com*/ zip.write(mapEntry.getValue()); zip.closeEntry(); } zip.close(); HttpHeaders headers = new HttpHeaders(); headers.add("Content-Type", "application/zip"); headers.add("Content-Disposition", "attachment; filename=\"" + request.getArtifactId() + ".zip\""); return new ResponseEntity<>(stream.toByteArray(), headers, HttpStatus.OK); }
From source file:org.codehaus.cargo.module.JarArchiveTest.java
/** * Verifies that the method <code>expandToPath()</code> works. * //from w ww. j av a 2 s . com * @throws Exception If an unexpected error occurs */ public void testExpandToPath() throws Exception { FileObject testJar = this.fsManager.resolveFile("ram:///test.jar"); ZipOutputStream zos = new ZipOutputStream(testJar.getContent().getOutputStream()); ZipEntry zipEntry = new ZipEntry("rootResource.txt"); zos.putNextEntry(zipEntry); zos.write("Some content".getBytes("UTF-8")); zos.closeEntry(); zos.close(); DefaultJarArchive jarArchive = new DefaultJarArchive("ram:///test.jar"); jarArchive.setFileHandler(new VFSFileHandler(this.fsManager)); jarArchive.expandToPath("ram:///test"); // Verify that the rootResource.txt file has been correctly expanded assertTrue(this.fsManager.resolveFile("ram:///test/rootResource.txt").exists()); }
From source file:com.ftb2om2.util.Zipper.java
private void addToZip(String path, String name, ZipOutputStream zos) throws IOException { File file = new File(path); FileInputStream fis = new FileInputStream(file); ZipEntry zipEntry = new ZipEntry(name); zos.putNextEntry(zipEntry);/*from w ww . jav a 2s.c om*/ byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); fis.close(); }
From source file:ee.ria.xroad.common.messagelog.archive.LogArchiveCache.java
private void addLinkingInfoToArchive(ZipOutputStream zipOut) throws IOException { ZipEntry linkingInfoEntry = new ZipEntry("linkinginfo"); zipOut.putNextEntry(linkingInfoEntry); zipOut.write(linkingInfoBuilder.build()); zipOut.closeEntry(); linkingInfoBuilder.afterArchiveCreated(); }