List of usage examples for java.util.zip ZipOutputStream putNextEntry
public void putNextEntry(ZipEntry e) throws IOException
From source file:gov.nih.nci.caarray.services.external.v1_0.data.JavaDataApiUtils.java
/** * {@inheritDoc}/*from w w w.j av a2 s .co m*/ */ public void copyFileContentsZipToOutputStream(Iterable<CaArrayEntityReference> fileRefs, OutputStream ostream) throws InvalidReferenceException, DataTransferException, IOException { ZipOutputStream zos = new ZipOutputStream(ostream); for (CaArrayEntityReference fileRef : fileRefs) { FileStreamableContents fsContents = dataService.streamFileContents(fileRef, true); zos.putNextEntry(new ZipEntry(fsContents.getMetadata().getName())); readFully(fsContents.getContentStream(), zos, true); } zos.finish(); }
From source file:Main.java
public void doZip(String filename, String zipfilename) throws Exception { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf, 0, buf.length);/* w w w . j av a 2 s. com*/ CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream((OutputStream) new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long) buf.length); entry.setMethod(ZipEntry.DEFLATED); crc.reset(); crc.update(buf); entry.setCrc(crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); }
From source file:Main.java
public void doZip(String filename, String zipfilename) throws Exception { byte[] buf = new byte[1024]; FileInputStream fis = new FileInputStream(filename); fis.read(buf, 0, buf.length);/*from w ww . ja v a2 s . c om*/ CRC32 crc = new CRC32(); ZipOutputStream s = new ZipOutputStream((OutputStream) new FileOutputStream(zipfilename)); s.setLevel(6); ZipEntry entry = new ZipEntry(filename); entry.setSize((long) buf.length); entry.setTime(new Date().getTime()); crc.reset(); crc.update(buf); entry.setCrc(crc.getValue()); s.putNextEntry(entry); s.write(buf, 0, buf.length); s.finish(); s.close(); }
From source file:md.archivers.ZIPArchiver.java
private void zipDirectory(File zipFile, File directory) throws FileNotFoundException, IOException { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); FileInputStream fin = null;//w ww . jav a 2 s . com for (File d : directory.listFiles()) { for (File f : d.listFiles()) { zos.putNextEntry(new ZipEntry(createNameForZip(f))); try { fin = new FileInputStream(f); IOUtils.copy(fin, zos); } finally { if (fin != null) fin.close(); } zos.closeEntry(); } } zos.close(); }
From source file:abfab3d.io.output.SVXWriter.java
/** * Writes a grid out to an svx file/*w w w . ja va 2 s . co m*/ * @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:com.joliciel.lefff.LefffMemoryLoader.java
public void serializeMemoryBase(LefffMemoryBase memoryBase, File memoryBaseFile) { LOG.debug("serializeMemoryBase"); boolean isZip = false; if (memoryBaseFile.getName().endsWith(".zip")) isZip = true;// w w w .jav a 2s . c o m FileOutputStream fos = null; ObjectOutputStream out = null; ZipOutputStream zos = null; try { fos = new FileOutputStream(memoryBaseFile); if (isZip) { zos = new ZipOutputStream(fos); zos.putNextEntry(new ZipEntry("lefff.obj")); out = new ObjectOutputStream(zos); } else { out = new ObjectOutputStream(fos); } try { out.writeObject(memoryBase); } finally { out.flush(); out.close(); } } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.export.ExportRunnable.java
private void processDataProviders(final DataProviderCollection exportableCollection, final ZipOutputStream zipout, final IProgressMonitor monitor) throws IOException { final ZipEntry entry = new ZipEntry(DATA_FILENAME); zipout.putNextEntry(entry); final PrintWriter pw = new PrintWriter(zipout); final DataCategory[] categories = exportableCollection.getSortedCategories(); for (int i = 0; i < categories.length; i++) { final DataProviderWrapper[] providersForCurrentCategory = exportableCollection .getSortedProvidersForCategory(categories[i]); for (int j = 0; j < providersForCurrentCategory.length; j++) { if (monitor.isCanceled()) { return; }// w w w . j ava 2s . c o m /* * Do not use localized data - this is for consumption by our * support staff */ final String data = (String) Adapters.get(providersForCurrentCategory[j].getDataNOLOC(), String.class, false); if (data != null) { final String messageFormat = //@formatter:off Messages.getString("ExportRunnable.CategoryOutputFormat", //$NON-NLS-1$ DiagnosticLocale.SUPPORT_LOCALE); //@formatter:on final String message = MessageFormat.format(messageFormat, categories[i].getLabelNOLOC(), providersForCurrentCategory[j].getDataProviderInfo().getLabelNOLOC()); pw.println(message); pw.println(); pw.println(data); pw.println(); } monitor.worked(1); } } pw.flush(); }
From source file:com.yunmel.syncretic.utils.io.IOUtils.java
private static void compressFile(File file, String fileName, ZipOutputStream zipout, String baseDir) { try {//from w ww. j ava 2s .com ZipEntry entry = null; if (baseDir.equals("/")) { baseDir = ""; } String filename = new String((baseDir + fileName).getBytes(), "GBK"); entry = new ZipEntry(filename); entry.setSize(file.length()); zipout.putNextEntry(entry); BufferedInputStream fr = new BufferedInputStream(new FileInputStream(file)); int len; byte[] buffer = new byte[1024]; while ((len = fr.read(buffer)) != -1) zipout.write(buffer, 0, len); fr.close(); } catch (IOException e) { } }
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();//from w ww . ja v a 2 s .c o m linkingInfoBuilder.afterArchiveCreated(); }
From source file:com.eviware.soapui.impl.wsdl.support.FileAttachment.java
public void cacheFileLocally(File file) throws FileNotFoundException, IOException { // write attachment-data to tempfile ByteArrayOutputStream data = new ByteArrayOutputStream(); ZipOutputStream out = new ZipOutputStream(data); out.putNextEntry(new ZipEntry(config.getName())); InputStream in = new FileInputStream(file); long sz = file.length(); config.setSize(sz);//ww w . j av a2s .com Tools.writeAll(out, in); in.close(); out.closeEntry(); out.finish(); out.close(); data.close(); config.setData(data.toByteArray()); }