List of usage examples for java.util.zip ZipOutputStream putNextEntry
public void putNextEntry(ZipEntry e) throws IOException
From source file:com.mobicage.rogerthat.mfr.dal.Streamable.java
public String toBase64() { try {/*from w w w . ja v a 2 s.c om*/ ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ZipOutputStream zip = new ZipOutputStream(bos); try { zip.setLevel(9); zip.putNextEntry(new ZipEntry("entry")); try { ObjectOutput out = new ObjectOutputStream(zip); try { out.writeObject(this); } finally { out.flush(); } } finally { zip.closeEntry(); } zip.flush(); return Base64.encodeBase64URLSafeString(bos.toByteArray()); } finally { zip.close(); } } finally { bos.close(); } } catch (IOException e) { log.log((Level.SEVERE), "IO Error while serializing member", e); return null; } }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
private static void zipDir(File sourceDir, final File destFile, ZipOutputStream zos) throws IOException { File[] dirList = sourceDir.listFiles(new FileFilter() { public boolean accept(File f) { return !f.getName().endsWith(destFile.getName()); }//from w ww.ja v a 2s . co m }); for (int i = 0; i < dirList.length; i++) { File f = dirList[i]; if (f.isDirectory()) { zipDir(f, destFile, zos); } else { int bytesIn = 0; byte[] readBuffer = new byte[2156]; FileInputStream fis = new FileInputStream(f); ZipEntry entry = new ZipEntry(sourceDir.getName() + File.separator + f.getName()); zos.putNextEntry(entry); while ((bytesIn = fis.read(readBuffer)) != -1) { zos.write(readBuffer, 0, bytesIn); } fis.close(); } } }
From source file:com.smash.revolance.ui.model.helper.ArchiveHelper.java
public static File buildArchive(File archive, File... files) throws FileNotFoundException { FileOutputStream fos = new FileOutputStream(archive); ZipOutputStream zos = new ZipOutputStream(fos); int bytesRead; byte[] buffer = new byte[1024]; CRC32 crc = new CRC32(); for (File file : files) { if (!file.exists()) { System.err.println("Skipping: " + file); continue; }/* ww w . j ava2 s. c o m*/ BufferedInputStream bis = null; try { bis = new BufferedInputStream(new FileInputStream(file)); crc.reset(); while ((bytesRead = bis.read(buffer)) != -1) { crc.update(buffer, 0, bytesRead); } bis.close(); // Reset to beginning of input stream bis = new BufferedInputStream(new FileInputStream(file)); String entryPath = FileHelper.getRelativePath(archive.getParentFile(), file); ZipEntry entry = new ZipEntry(entryPath); entry.setMethod(ZipEntry.STORED); entry.setCompressedSize(file.length()); entry.setSize(file.length()); entry.setCrc(crc.getValue()); zos.putNextEntry(entry); while ((bytesRead = bis.read(buffer)) != -1) { zos.write(buffer, 0, bytesRead); } } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } finally { IOUtils.closeQuietly(bis); } } IOUtils.closeQuietly(zos); return archive; }
From source file:gov.nih.nci.caarray.services.external.v1_0.data.AbstractDataApiUtils.java
/** * {@inheritDoc}/*from w ww . java 2 s .c om*/ */ public void copyMageTabZipToOutputStream(CaArrayEntityReference experimentRef, OutputStream ostream) throws InvalidReferenceException, DataTransferException, IOException { MageTabFileSet mtset = exportMageTab(experimentRef); ZipOutputStream zos = new ZipOutputStream(ostream); zos.putNextEntry(new ZipEntry(mtset.getIdf().getMetadata().getName())); IOUtils.write(mtset.getIdf().getContents(), zos); zos.putNextEntry(new ZipEntry(mtset.getSdrf().getMetadata().getName())); IOUtils.write(mtset.getSdrf().getContents(), zos); for (gov.nih.nci.caarray.external.v1_0.data.File dataFile : mtset.getDataFiles()) { zos.putNextEntry(new ZipEntry(dataFile.getMetadata().getName())); copyFileContentsToOutputStream(dataFile.getReference(), false, zos); } zos.finish(); }
From source file:io.apigee.buildTools.enterprise4g.utils.ZipUtils.java
static void addDir(File dirObj, ZipOutputStream out, File root, String prefix) 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, root, prefix); continue; }/*from www.j ava 2s. co m*/ FileInputStream in = new FileInputStream(files[i].getAbsolutePath()); log.debug(" Adding: " + files[i].getAbsolutePath()); String relativePath = files[i].getCanonicalPath().substring(root.getCanonicalPath().length()); while (relativePath.startsWith("/")) { relativePath = relativePath.substring(1); } while (relativePath.startsWith("\\")) { relativePath = relativePath.substring(1); } String left = Matcher.quoteReplacement("\\"); String right = Matcher.quoteReplacement("/"); relativePath = relativePath.replaceAll(left, right); relativePath = (prefix == null) ? relativePath : prefix + "/" + relativePath; out.putNextEntry(new ZipEntry(relativePath)); int len; while ((len = in.read(tmpBuf)) > 0) { out.write(tmpBuf, 0, len); } out.closeEntry(); in.close(); } }
From source file:com.joliciel.talismane.machineLearning.linearsvm.LinearSVMModel.java
@Override public void writeDataToStream(ZipOutputStream zos) { try {//from w ww. j a v a2s. c o m zos.putNextEntry(new ZipEntry("featureIndexMap.obj")); ObjectOutputStream out = new ObjectOutputStream(zos); try { out.writeObject(featureIndexMap); } finally { out.flush(); } zos.flush(); zos.putNextEntry(new ZipEntry("outcomes.obj")); out = new ObjectOutputStream(zos); try { out.writeObject(outcomes); } finally { out.flush(); } zos.flush(); } catch (IOException e) { LogUtils.logError(LOG, e); throw new RuntimeException(e); } }
From source file:com.joliciel.talismane.parser.ParsingConstrainerImpl.java
@Override public void onCompleteParse() { if (this.transitionSystem == null) this.transitionSystem = TalismaneSession.getTransitionSystem(); if (this.file != null) { try {/*from w w w . j ava2s .c om*/ ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(file, false)); zos.putNextEntry(new ZipEntry("ParsingConstrainer.obj")); ObjectOutputStream oos = new ObjectOutputStream(zos); try { oos.writeObject(this); } finally { oos.flush(); } zos.flush(); zos.close(); } catch (IOException ioe) { LogUtils.logError(LOG, ioe); throw new RuntimeException(ioe); } } }
From source file:eu.europa.ejusticeportal.dss.controller.action.DownloadSignedPdf.java
/** * @param sf// w w w . j ava 2 s .c o m * @param response * @throws IOException */ private void writeZip(SignedForm sf, HttpServletResponse response, String fileName) throws IOException { ZipOutputStream zos = new ZipOutputStream(response.getOutputStream()); ZipEntry ze = new ZipEntry(fileName); zos.putNextEntry(ze); zos.write(sf.getDocument()); ze = new ZipEntry(fileName + ".xml"); zos.putNextEntry(ze); zos.write(sf.getDetachedSignature()); zos.closeEntry(); zos.close(); }
From source file:com.intuit.tank.service.impl.v1.agent.AgentServiceV1.java
private void addFileToZip(String name, InputStream in, ZipOutputStream zip) throws Exception { try {//from w w w.j a v a 2 s.co m zip.putNextEntry(new ZipEntry(name)); IOUtils.copy(in, zip); } finally { IOUtils.closeQuietly(in); } }
From source file:com.epam.wilma.message.search.web.support.FileZipper.java
private void putZipEntryToStream(final ZipOutputStream zipStream, final String fileName) throws IOException { try {// w w w .j a v a 2s. co m ZipEntry zipEntry = entryFactory.createZipEntry(fileName); zipStream.putNextEntry(zipEntry); } catch (ZipException e) { logger.warn("Exception occurred while creating zip stream from file: " + fileName, e); putZipEntryToStream(zipStream, "1_" + fileName); } }