Java Code Examples for java.util.zip.ZipOutputStream
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project azkaban, under directory /azkaban-common/src/java/azkaban/common/utils/.
Source file: Utils.java

public static void zip(File input,File output) throws IOException { FileOutputStream out=new FileOutputStream(output); ZipOutputStream zOut=new ZipOutputStream(out); zipFile("",input,zOut); zOut.close(); }
Example 2
public String zipFile(File baseDir,File fileToCompress) throws IOException { checkArgument(fileToCompress.isFile(),"File should be a file: " + fileToCompress); ByteArrayOutputStream bos=new ByteArrayOutputStream(); ZipOutputStream zos=new ZipOutputStream(bos); try { addToZip(baseDir.getAbsolutePath(),zos,fileToCompress); return new Base64Encoder().encode(bos.toByteArray()); } finally { Closeables.closeQuietly(zos); Closeables.closeQuietly(bos); } }
Example 3
From project genobyte, under directory /genobyte/src/main/java/org/obiba/bitwise/util/.
Source file: BitwiseDiskUtil.java

/** * Writes multiple bitwise stores to a zip file. The output file will be overwritten. * @param zipFile the zip file to create and write to. * @param names an array of unique bitwise stores to add to the zip file * @throws IOException when an error occurs */ public static void zipStores(File zipFile,String... names) throws IOException { ZipOutputStream zos=null; try { zos=new ZipOutputStream(new FileOutputStream(zipFile)); zos.setLevel(ZipOutputStream.STORED); for ( String name : names) { zipStore(name,zos); } } finally { if (zos != null) zos.close(); } }
Example 4
From project cloudbees-api-client, under directory /cloudbees-api-client/src/main/java/com/cloudbees/upload/.
Source file: ArchiveUtils.java

private static void archiveDirectory(String directory,String archiveFile) throws IOException { File archive=new File(archiveFile); archive.createNewFile(); FileOutputStream fileOutputStream=new FileOutputStream(archive); ZipOutputStream zipOutputStream=new ZipOutputStream(new BufferedOutputStream(fileOutputStream)); ZipHelper.addDirectoryToZip(new File(directory),new File(directory),null,zipOutputStream); zipOutputStream.close(); }
Example 5
From project as3-commons-jasblocks, under directory /src/test/java/org/as3commons/asblocks/impl/.
Source file: TestSWCResourceRoot.java

private void createTextSWC(File file) throws FileNotFoundException, IOException { ZipEntry catalogEntry=new ZipEntry("catalog.xml"); FileOutputStream out=new FileOutputStream(file); file.deleteOnExit(); ZipOutputStream zip=new ZipOutputStream(out); zip.putNextEntry(catalogEntry); OutputStreamWriter writer=new OutputStreamWriter(zip); writer.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<swc xmlns=\"http://www.adobe.com/flash/swccatalog/9\">" + " <versions>"+ " <swc version=\"1.0\"/>"+ " <flex version=\"2.0\" build=\"0\"/>"+ " </versions>"+ " <features>"+ " <feature-script-deps/>"+ " <feature-components/>"+ " <feature-files/>"+ " </features>"+ " <libraries>"+ " <library path=\"library.swf\">"+ " <script name=\"EventWrecker\" mod=\"1234567890123\">"+ " <def id=\"flashy.events:EventWrecker\"/>"+ " <def id=\"NoPackage\"/>"+ " <dep id=\"Object\" type=\"i\"/>"+ " </script>"+ " </library>"+ " </libraries>"+ " <files>"+ " </files>"+ "</swc>"); writer.flush(); zip.close(); }
Example 6
From project des, under directory /daemon/lib/apache-log4j-1.2.16/tests/src/java/org/apache/log4j/.
Source file: PropertyConfiguratorTest.java

/** * Test for bug 47465. configure(URL) did not close opened JarURLConnection. * @throws IOException if IOException creating properties jar. */ public void testJarURL() throws IOException { File dir=new File("output"); dir.mkdirs(); File file=new File("output/properties.jar"); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); zos.putNextEntry(new ZipEntry(LogManager.DEFAULT_CONFIGURATION_FILE)); zos.write("log4j.rootLogger=debug".getBytes()); zos.closeEntry(); zos.close(); URL url=new URL("jar:" + file.toURL() + "!/"+ LogManager.DEFAULT_CONFIGURATION_FILE); PropertyConfigurator.configure(url); assertTrue(file.delete()); assertFalse(file.exists()); }
Example 7
From project dolphin, under directory /dolphinmaple/src/com/tan/util/.
Source file: ZipUtils.java

/** * ????????????? * @param resFileList ???????????????? * @param zipFile ?????????? * @throws IOException ??????????????? */ public static void zipFiles(Collection<File> resFileList,File zipFile) throws IOException { ZipOutputStream zipout=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipFile),BUFF_SIZE)); for ( File resFile : resFileList) { zipFile(resFile,zipout,""); } zipout.close(); }
Example 8
From project flyingsaucer, under directory /flying-saucer-core/src/main/java/org/xhtmlrenderer/util/.
Source file: Zipper.java

public File zipDirectory() throws IOException { ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(outputFile)); recurseAndZip(sourceDir,zos); zos.close(); return outputFile; }
Example 9
From project GenericKnimeNodes, under directory /com.genericworkflownodes.knime.base_plugin/src/com/genericworkflownodes/knime/nodes/io/exporter/.
Source file: MimeFileExporterNodeModel.java

/** * {@inheritDoc} */ @Override protected void saveInternals(final File internDir,final ExecutionMonitor exec) throws IOException, CanceledExecutionException { ZipOutputStream out=new ZipOutputStream(new FileOutputStream(new File(internDir,"loadeddata"))); ZipEntry entry=new ZipEntry("rawdata.bin"); out.putNextEntry(entry); out.write(data.getBytes()); out.close(); }
Example 10
From project gxa, under directory /atlas-web/src/main/java/uk/ac/ebi/gxa/requesthandlers/dump/.
Source file: GeneEbeyeDumpRequestHandler.java

/** * Generates a zip file containing to be used in EB-eye. The zip file contains two xml files, one containing genes, and one containing experiments data. */ @Transactional public void dumpEbeyeData(){ ZipOutputStream outputStream=null; try { outputStream=new ZipOutputStream(new FileOutputStream(ebeyeDumpFile)); dumpExperimentsForEbeye(outputStream); dumpGenesForEbeye(outputStream); } catch ( IOException e) { log.error("Couldn't write to " + ebeyeDumpFile.getAbsolutePath(),e); } finally { closeQuietly(outputStream); } }
Example 11
From project hadoop_framework, under directory /core/src/main/java/com/lightboxtechnologies/spectrum/.
Source file: HDFSArchiver.java

protected static void zip(FileSystem fs,Path src,OutputStream out) throws IOException { final byte[] buf=new byte[4096]; ZipOutputStream zout=null; try { zout=new ZipOutputStream(out); zout.setLevel(9); traverse(fs,src,zout,buf); zout.close(); } finally { IOUtils.closeQuietly(zout); } }
Example 12
From project Hphoto, under directory /src/java/com/hphoto/server/.
Source file: DownloadProgram.java

public static void main(String[] arg) throws IOException { OutputStream out=new FileOutputStream(file); ZipOutputStream zipos=new ZipOutputStream(out); zipos.putNextEntry(new ZipEntry(readme)); InputStream in=new FileInputStream(readme); if (in != null) { write(in,zipos); } else { System.out.println("not input file"); } zipos.closeEntry(); zipos.close(); }
Example 13
From project jPOS, under directory /jpos/src/main/java/org/jpos/util/.
Source file: DailyLogListener.java

/** * Hook method that creates an output stream that will compress the data. * @param f the file name * @return ZIP/GZip OutputStream * @throws java.io.IOException on error */ protected OutputStream getCompressedOutputStream(File f) throws IOException { OutputStream os=new BufferedOutputStream(new FileOutputStream(f)); if (getCompressionFormat() == ZIP) { ZipOutputStream ret=new ZipOutputStream(os); ret.putNextEntry(new ZipEntry(logName)); return ret; } else { return new GZIPOutputStream(os); } }
Example 14
From project kernel_1, under directory /exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/io/.
Source file: ZipUtil.java

public ByteArrayOutputStream addToArchive(InputStream input,String entryName) throws Exception { ByteArrayOutputStream output=new ByteArrayOutputStream(); ZipOutputStream zipOutput=new ZipOutputStream(output); addToArchive(zipOutput,input,entryName); zipOutput.close(); return output; }
Example 15
From project log4j, under directory /tests/src/java/org/apache/log4j/.
Source file: PropertyConfiguratorTest.java

/** * Test for bug 47465. configure(URL) did not close opened JarURLConnection. * @throws IOException if IOException creating properties jar. */ public void testJarURL() throws IOException { File dir=new File("output"); dir.mkdirs(); File file=new File("output/properties.jar"); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); zos.putNextEntry(new ZipEntry(LogManager.DEFAULT_CONFIGURATION_FILE)); zos.write("log4j.rootLogger=debug".getBytes()); zos.closeEntry(); zos.close(); URL url=new URL("jar:" + file.toURL() + "!/"+ LogManager.DEFAULT_CONFIGURATION_FILE); PropertyConfigurator.configure(url); assertTrue(file.delete()); assertFalse(file.exists()); }
Example 16
From project log4jna, under directory /thirdparty/log4j/tests/src/java/org/apache/log4j/.
Source file: PropertyConfiguratorTest.java

/** * Test for bug 47465. configure(URL) did not close opened JarURLConnection. * @throws IOException if IOException creating properties jar. */ public void testJarURL() throws IOException { File dir=new File("output"); dir.mkdirs(); File file=new File("output/properties.jar"); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); zos.putNextEntry(new ZipEntry(LogManager.DEFAULT_CONFIGURATION_FILE)); zos.write("log4j.rootLogger=debug".getBytes()); zos.closeEntry(); zos.close(); URL url=new URL("jar:" + file.toURL() + "!/"+ LogManager.DEFAULT_CONFIGURATION_FILE); PropertyConfigurator.configure(url); assertTrue(file.delete()); assertFalse(file.exists()); }
Example 17
From project maven-wagon, under directory /wagon-providers/wagon-ssh-common/src/main/java/org/apache/maven/wagon/providers/ssh/.
Source file: ScpHelper.java

public static void createZip(List<String> files,File zipName,File basedir) throws IOException { ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(zipName)); try { for ( String file : files) { file=file.replace('\\','/'); writeZipEntry(zos,new File(basedir,file),file); } } finally { IOUtil.close(zos); } }
Example 18
From project mylyn.docs, under directory /org.eclipse.mylyn.docs.epub.core/src/org/eclipse/mylyn/internal/docs/epub/core/.
Source file: EPUBFileUtil.java

/** * Recursively compresses contents of the given folder into a zip-file. If a file already exists in the given location an exception will be thrown. * @param destination the destination file * @param folder the source folder * @param uncompressed a list of files to keep uncompressed * @throws ZipException * @throws IOException */ public static void zip(File destination,File folder) throws ZipException, IOException { if (destination.exists()) { throw new IOException("A file already exists at " + destination.getAbsolutePath()); } ZipOutputStream out=new ZipOutputStream(new FileOutputStream(destination)); writeEPUBHeader(out); zip(folder,folder,out); out.close(); }
Example 19
From project niravCS2103, under directory /CS2103/lib/apache-log4j-1.2.16/tests/src/java/org/apache/log4j/.
Source file: PropertyConfiguratorTest.java

/** * Test for bug 47465. configure(URL) did not close opened JarURLConnection. * @throws IOException if IOException creating properties jar. */ public void testJarURL() throws IOException { File dir=new File("output"); dir.mkdirs(); File file=new File("output/properties.jar"); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); zos.putNextEntry(new ZipEntry(LogManager.DEFAULT_CONFIGURATION_FILE)); zos.write("log4j.rootLogger=debug".getBytes()); zos.closeEntry(); zos.close(); URL url=new URL("jar:" + file.toURL() + "!/"+ LogManager.DEFAULT_CONFIGURATION_FILE); PropertyConfigurator.configure(url); assertTrue(file.delete()); assertFalse(file.exists()); }
Example 20
From project nuxeo-common, under directory /src/main/java/org/nuxeo/common/utils/.
Source file: ZipUtils.java

public static void zip(File[] files,OutputStream out,String prefix) throws IOException { ZipOutputStream zout=null; try { zout=new ZipOutputStream(out); _zip(files,zout,prefix); } finally { if (zout != null) { zout.finish(); } } }
Example 21
From project nuxeo-platform-rendering-templates, under directory /src/main/java/org/nuxeo/ecm/platform/template/odt/.
Source file: OOoArchiveModifier.java

protected void mkOOoZip(File directory,File outFile) throws Exception { ZipOutputStream zipOutputStream=new ZipOutputStream(new FileOutputStream(outFile)); File manif=new File(directory,"mimetype"); writeOOoEntry(zipOutputStream,manif.getName(),manif,ZipEntry.STORED); for ( File fileEntry : directory.listFiles()) { if (!fileEntry.getName().equals(manif.getName())) { writeOOoEntry(zipOutputStream,fileEntry.getName(),fileEntry,ZipEntry.DEFLATED); } } zipOutputStream.close(); }
Example 22
From project nuxeo-tycho-osgi, under directory /nuxeo-common/src/main/java/org/nuxeo/common/utils/.
Source file: ZipUtils.java

public static void zip(File[] files,OutputStream out,String prefix) throws IOException { ZipOutputStream zout=null; try { zout=new ZipOutputStream(out); _zip(files,zout,prefix); } finally { if (zout != null) { zout.finish(); } } }
Example 23
From project plexus-io, under directory /src/test/java/org/codehaus/plexus/components/io/filemappers/.
Source file: ResourcesTest.java

private void createZipFile(File dest,File dir) throws IOException { FileOutputStream fos=new FileOutputStream(dest); ZipOutputStream zos=new ZipOutputStream(fos); addDirToZipFile(zos,dir,null); zos.close(); }
Example 24
From project ALP, under directory /workspace/alp-utils/src/main/java/com/lohika/alp/utils/zip/.
Source file: Zip.java

/** * Instantiates a new zip. * @param in_zipFileLocation the in_zip file location */ public Zip(String in_zipFileLocation){ zipFileLocation=in_zipFileLocation; try { dest=new FileOutputStream(zipFileLocation); } catch ( FileNotFoundException e) { e.printStackTrace(); } checksum=new CheckedOutputStream(dest,new Adler32()); out=new ZipOutputStream(new BufferedOutputStream(checksum)); }
Example 25
From project and-bible, under directory /jsword-tweaks/src/util/java/net/andbible/util/.
Source file: MJDIndexAll.java

private void createZipFile(File jarFile,File sourceDir){ try { BufferedInputStream origin=null; FileOutputStream dest=new FileOutputStream(jarFile); ZipOutputStream out=new ZipOutputStream(new BufferedOutputStream(dest)); byte data[]=new byte[JAR_BUFFER_SIZE]; File files[]=sourceDir.listFiles(); for (int i=0; i < files.length; i++) { System.out.println("Adding: " + files[i]); FileInputStream fi=new FileInputStream(files[i]); origin=new BufferedInputStream(fi,JAR_BUFFER_SIZE); ZipEntry entry=new ZipEntry(files[i].getName()); out.putNextEntry(entry); int count; while ((count=origin.read(data,0,JAR_BUFFER_SIZE)) != -1) { out.write(data,0,count); } origin.close(); } out.close(); } catch ( Exception e) { e.printStackTrace(); } }
Example 26
From project andlytics, under directory /src/com/github/andlyticsproject/io/.
Source file: ExportService.java

private boolean exportStats(){ String message=getApplicationContext().getString(R.string.export_started); sendNotification(message); File dir=StatsCsvReaderWriter.getExportDir(); if (!dir.exists()) { dir.mkdirs(); } try { File zipFile=StatsCsvReaderWriter.getExportFileForAccount(accountName); ZipOutputStream zip=new ZipOutputStream(new FileOutputStream(zipFile)); StatsCsvReaderWriter statsWriter=new StatsCsvReaderWriter(this); ContentAdapter db=new ContentAdapter(this); try { for (int i=0; i < packageNames.length; i++) { AppStatsList statsForApp=db.getStatsForApp(packageNames[i],Timeframe.UNLIMITED,false); statsWriter.writeStats(packageNames[i],statsForApp.getAppStats(),zip); } } catch ( IOException e) { Log.d(TAG,"Zip error, deleting incomplete file."); zipFile.delete(); } finally { zip.close(); } Utils.scanFile(this,zipFile.getAbsolutePath()); } catch ( IOException e) { Log.e(TAG,"Error zipping CSV files: " + e.getMessage(),e); return false; } return !errors; }
Example 27
From project Android-File-Manager, under directory /src/com/nexes/manager/.
Source file: FileManager.java

/** * @param path */ public void createZipFile(String path){ File dir=new File(path); String[] list=dir.list(); String name=path.substring(path.lastIndexOf("/"),path.length()); String _path; if (!dir.canRead() || !dir.canWrite()) return; int len=list.length; if (path.charAt(path.length() - 1) != '/') _path=path + "/"; else _path=path; try { ZipOutputStream zip_out=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(_path + name + ".zip"),BUFFER)); for (int i=0; i < len; i++) zip_folder(new File(_path + list[i]),zip_out); zip_out.close(); } catch ( FileNotFoundException e) { Log.e("File not found",e.getMessage()); } catch ( IOException e) { Log.e("IOException",e.getMessage()); } }
Example 28
From project Android-File-Manager-Tablet, under directory /src/com/nexes/manager/tablet/.
Source file: FileManager.java

/** * @param path */ public void createZipFile(String path){ File dir=new File(path); String[] list=dir.list(); String name=path.substring(path.lastIndexOf("/"),path.length()); String _path; if (!dir.canRead() || !dir.canWrite()) return; int len=list.length; if (path.charAt(path.length() - 1) != '/') _path=path + "/"; else _path=path; try { ZipOutputStream zip_out=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(_path + name + ".zip"),BUFFER)); for (int i=0; i < len; i++) zip_folder(new File(_path + list[i]),zip_out); zip_out.close(); } catch ( FileNotFoundException e) { Log.e("File not found",e.getMessage()); } catch ( IOException e) { Log.e("IOException",e.getMessage()); } }
Example 29
From project Arecibo, under directory /util/src/main/java/com/ning/arecibo/util/.
Source file: ZipUtils.java

public static byte[] zip(byte[] input) throws IOException { ByteArrayOutputStream o=out.get(); o.reset(); ZipOutputStream z=null; try { z=new ZipOutputStream(o); z.putNextEntry(new ZipEntry("entry.xml")); z.write(input); z.closeEntry(); z.flush(); } finally { if (z != null) { z.close(); } } return o.toByteArray(); }
Example 30
From project aviator, under directory /src/main/java/com/googlecode/aviator/asm/optimizer/.
Source file: JarOptimizer.java

static void optimize(final File f) throws IOException { if (f.isDirectory()) { File[] files=f.listFiles(); for (int i=0; i < files.length; ++i) { optimize(files[i]); } } else if (f.getName().endsWith(".jar")) { File g=new File(f.getParentFile(),f.getName() + ".new"); ZipFile zf=new ZipFile(f); ZipOutputStream out=new ZipOutputStream(new FileOutputStream(g)); Enumeration e=zf.entries(); byte[] buf=new byte[10000]; while (e.hasMoreElements()) { ZipEntry ze=(ZipEntry)e.nextElement(); if (ze.isDirectory()) { continue; } out.putNextEntry(ze); InputStream is=zf.getInputStream(ze); int n; do { n=is.read(buf,0,buf.length); if (n != -1) { out.write(buf,0,n); } } while (n != -1); out.closeEntry(); } out.close(); zf.close(); f.delete(); g.renameTo(f); } }
Example 31
From project Baseform-Epanet-Java-Library, under directory /src/org/addition/epanet/util/.
Source file: XLSXWriter.java

public void save(OutputStream outputStream) throws IOException { zos=new ZipOutputStream(outputStream); zos.setLevel(1); writer=new BufferedWriter(new OutputStreamWriter(zos,"UTF-8")); createRels(); creatContentType(); createXL_rel(); createWorkbookXML(); createSharedStringsXML(); for (int i=0; i < sheets.size(); i++) { Spreadsheet sheet=sheets.get(i); createWorksheet(sheet,i + 1); } }
Example 32
From project bpelunit, under directory /net.bpelunit.framework.control.deploy.activevos9/src/main/java/net/bpelunit/util/.
Source file: ZipUtil.java

public static void zipDirectory(File directory,File zipFile) throws IOException { @SuppressWarnings("unchecked") Collection<File> files=FileUtils.listFiles(directory,null,true); FileOutputStream fzos=null; ZipOutputStream zos=null; try { fzos=new FileOutputStream(zipFile); zos=new ZipOutputStream(fzos); for ( File f : files) { String fileNameInZIP=directory.toURI().relativize(f.toURI()).getPath(); ZipEntry zipEntry=new ZipEntry(fileNameInZIP); zos.putNextEntry(zipEntry); FileInputStream fileInputStream=new FileInputStream(f); try { IOUtils.copy(fileInputStream,zos); } finally { IOUtils.closeQuietly(fileInputStream); } } } finally { IOUtils.closeQuietly(zos); IOUtils.closeQuietly(fzos); } }
Example 33
From project candlepin, under directory /src/main/java/org/candlepin/sync/.
Source file: Exporter.java

private File createZipArchiveWithDir(File tempDir,File exportDir,String exportFileName,String comment) throws FileNotFoundException, IOException { File archive=new File(tempDir,exportFileName); ZipOutputStream out=null; try { out=new ZipOutputStream(new FileOutputStream(archive)); out.setComment(comment); addFilesToArchive(out,exportDir.getParent().length() + 1,exportDir); } finally { if (out != null) { out.close(); } } return archive; }
Example 34
From project cargo-maven2-plugin-db, under directory /src/test/java/org/codehaus/cargo/maven2/configuration/.
Source file: ContainerTest.java

public void testCreateEmbeddedContainerWithExtraClasspathDependency() throws Exception { String resourceValue="file in zip in dependency"; String resourceName="maven-test-my-dependency.txt"; File zipFile=File.createTempFile("maven2-plugin-test-dependency",".zip"); zipFile.deleteOnExit(); ZipOutputStream zip=new ZipOutputStream(new FileOutputStream(zipFile)); zip.putNextEntry(new ZipEntry(resourceName)); zip.write(resourceValue.getBytes()); zip.close(); DefaultArtifact artifact=new DefaultArtifact("customGroupId","customArtifactId",VersionRange.createFromVersion("0.1"),"compile","jar",null,new DefaultArtifactHandler()); artifact.setFile(zipFile); Set artifacts=new HashSet(); artifacts.add(artifact); Dependency dependencyElement=new Dependency(); dependencyElement.setGroupId("customGroupId"); dependencyElement.setArtifactId("customArtifactId"); dependencyElement.setType("jar"); org.codehaus.cargo.maven2.configuration.Container containerElement=setUpContainerElement(new EmbeddedLocalContainerStub()); containerElement.setDependencies(new Dependency[]{dependencyElement}); org.codehaus.cargo.container.EmbeddedLocalContainer container=(EmbeddedLocalContainer)containerElement.createContainer(new StandaloneLocalConfigurationStub("configuration/home"),new NullLogger(),createTestCargoProject("whatever",artifacts)); assertEquals(resourceValue,getResource(container.getClassLoader(),resourceName)); assertEquals(resourceValue,getResource(Thread.currentThread().getContextClassLoader(),resourceName)); }
Example 35
From project ceres, under directory /ceres-core/src/main/java/com/bc/ceres/core/runtime/internal/.
Source file: IOHelper.java

public static List<String> pack(File sourceDir,File targetZipFile,ProgressMonitor pm) throws IOException, CanceledException { if (!sourceDir.exists()) { throw new FileNotFoundException(sourceDir.getPath()); } DirScanner dirScanner=new DirScanner(sourceDir,true,true); String[] entryNames=dirScanner.scan(); ZipOutputStream zipOutputStream=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZipFile))); zipOutputStream.setMethod(ZipEntry.DEFLATED); pm.beginTask(MessageFormat.format("Packing {0} into {1}",sourceDir.getName(),targetZipFile.getName()),entryNames.length); ArrayList<String> entries=new ArrayList<String>(entryNames.length); try { for ( String entryName : entryNames) { checkIOTaskCanceled(pm); ZipEntry zipEntry=new ZipEntry(entryName.replace('\\','/')); pm.setSubTaskName(entryName); File sourceFile=new File(sourceDir,entryName); FileInputStream inputStream=new FileInputStream(sourceFile); try { zipOutputStream.putNextEntry(zipEntry); copy(inputStream,zipOutputStream,entryName,(int)sourceFile.length(),SubProgressMonitor.create(pm,1)); zipOutputStream.closeEntry(); entries.add(entryName); } finally { inputStream.close(); } } return entries; } finally { pm.done(); zipOutputStream.close(); } }
Example 36
From project ceylon-module-resolver, under directory /impl/src/main/java/com/redhat/ceylon/cmr/impl/.
Source file: IOUtils.java

static File zipFolder(File root) throws IOException { if (!root.isDirectory()) throw new IOException("Zip root must be a folder"); File zipFile=File.createTempFile("module-doc",".zip"); try { ZipOutputStream os=new ZipOutputStream(new FileOutputStream(zipFile)); try { for ( File f : root.listFiles()) zipInternal("",f,os); } finally { os.flush(); os.close(); } return zipFile; } catch ( IOException x) { zipFile.delete(); throw x; } }
Example 37
public static void saveSet(final File file,final String format,final Set<byte[]> set,final String sep) throws IOException { final File tf=new File(file.toString() + ".prt" + (System.currentTimeMillis() % 1000)); OutputStream os=null; if ((format == null) || (format.equals("plain"))) { os=new BufferedOutputStream(new FileOutputStream(tf)); } else if (format.equals("gzip")) { os=new GZIPOutputStream(new FileOutputStream(tf)); } else if (format.equals("zip")) { final ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); String name=file.getName(); if (name.endsWith(".zip")) name=name.substring(0,name.length() - 4); zos.putNextEntry(new ZipEntry(name + ".txt")); os=zos; } if (os != null) { for (final Iterator<byte[]> i=set.iterator(); i.hasNext(); ) { os.write(i.next()); if (sep != null) os.write(sep.getBytes("UTF-8")); } os.close(); } forceMove(tf,file); }
Example 38
From project CIShell, under directory /core/org.cishell.utilities/src/org/cishell/utilities/.
Source file: ZipUtilities.java

public static void zipFiles(Collection<File> files,File targetZipFile) throws ZipIOException { try { zipFiles(files,new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(targetZipFile)))); } catch ( FileNotFoundException e) { throw new ZipIOException(e.getMessage(),e); } }
Example 39
From project cloudhopper-commons-util, under directory /src/main/java/com/cloudhopper/commons/util/.
Source file: CompressionUtil.java

@Override public void compress(File srcFile,File destFile) throws IOException { FileInputStream in=null; ZipOutputStream out=null; try { in=new FileInputStream(srcFile); out=new ZipOutputStream(new FileOutputStream(destFile)); out.putNextEntry(new ZipEntry(srcFile.getName())); byte[] buf=new byte[1024]; int len; while ((len=in.read(buf)) > 0) { out.write(buf,0,len); } in.close(); in=null; out.closeEntry(); out.finish(); out.close(); out=null; } finally { if (in != null) { try { in.close(); } catch ( Exception e) { } } if (out != null) { logger.warn("Output stream for ZIP compressed file was not null -- indicates error with compression occurred"); try { out.close(); } catch ( Exception e) { } } } }
Example 40
From project cloudify, under directory /dsl/src/main/java/org/cloudifysource/dsl/internal/packaging/.
Source file: ZipUtils.java

/** * Zips a single source file into the given file. * @param sourceFile the file to zip. * @param zipfile the zip file to create. * @throws IOException in case of an error. */ public static void zipSingleFile(final File sourceFile,final File zipfile) throws IOException { if (!sourceFile.exists()) { throw new FileNotFoundException("Could not find: " + sourceFile); } if (!sourceFile.isFile()) { throw new IllegalArgumentException(sourceFile + " is not a file!"); } final File toZip=new File(zipfile,""); toZip.setWritable(true); final ZipOutputStream zout=new ZipOutputStream(new FileOutputStream(toZip)); try { final String name=sourceFile.getName(); zout.putNextEntry(new ZipEntry(name)); copy(sourceFile,zout); zout.closeEntry(); } finally { zout.close(); } }
Example 41
From project core_1, under directory /runtime/src/main/java/org/switchyard/internal/io/.
Source file: ZIPSerializer.java

/** * {@inheritDoc} */ @Override public <T>int serialize(T obj,Class<T> type,OutputStream out,int bufferSize) throws IOException { out=new CountingOutputStream(out); ZipOutputStream zip=new ZipOutputStream(out); try { zip.putNextEntry(new ZipEntry("z")); _serializer.serialize(obj,type,zip,bufferSize); zip.closeEntry(); zip.finish(); zip.flush(); } finally { if (isCloseEnabled()) { zip.close(); } } return ((CountingOutputStream)out).getCount(); }
Example 42
From project cp-common-utils, under directory /src/com/clarkparsia/common/io/.
Source file: Files2.java

/** * Zip the given directory. * @param theDir the directory to zip * @param theOutputFile the zip file to write to * @throws IOException thrown if there is an error while zipping the directory or while saving the results. */ public static void zipDirectory(File theDir,File theOutputFile) throws IOException { ZipOutputStream aZipOut=new ZipOutputStream(new FileOutputStream(theOutputFile)); try { Collection<File> aFileList=listFiles(theDir); String aPathToRemove=theDir.getAbsolutePath().substring(0,theDir.getAbsolutePath().lastIndexOf(File.separator)); for ( File aFile : aFileList) { FileInputStream aFileIn=new FileInputStream(aFile); try { ZipEntry aZipEntry=new ZipEntry(aFile.getAbsolutePath().substring(aFile.getAbsolutePath().indexOf(aPathToRemove) + aPathToRemove.length() + 1)); aZipOut.putNextEntry(aZipEntry); ByteStreams.copy(aFileIn,aZipOut); } finally { Closeables.closeQuietly(aFileIn); aZipOut.closeEntry(); } } } finally { Closeables.closeQuietly(aZipOut); } }
Example 43
From project datasalt-utils, under directory /src/contrib/java/org/apache/solr/hadoop/.
Source file: SolrOutputFormat.java

private static void createZip(File dir,File out) throws IOException { HashSet<File> files=new HashSet<File>(); for ( String allowedDirectory : SolrRecordWriter.getAllowedConfigDirectories()) { File configDir=new File(dir,allowedDirectory); boolean configDirExists; if (!(configDirExists=configDir.exists()) && SolrRecordWriter.isRequiredConfigDirectory(allowedDirectory)) { throw new IOException(String.format("required configuration directory %s is not present in %s",allowedDirectory,dir)); } if (!configDirExists) { continue; } listFiles(configDir,files); } out.delete(); int subst=dir.toString().length(); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(out)); byte[] buf=new byte[1024]; for ( File f : files) { ZipEntry ze=new ZipEntry(f.toString().substring(subst)); zos.putNextEntry(ze); InputStream is=new FileInputStream(f); int cnt; while ((cnt=is.read(buf)) >= 0) { zos.write(buf,0,cnt); } is.close(); zos.flush(); zos.closeEntry(); } zos.close(); }
Example 44
From project Eclipse, under directory /com.mobilesorcery.sdk.core/src/com/mobilesorcery/sdk/core/.
Source file: Util.java

private static void zip(File sourceDir,File targetZip,boolean isJar) throws IOException { ZipOutputStream output=createZipOutputStream(new FileOutputStream(targetZip),isJar); try { for ( File file : listFiles(sourceDir,true)) { if (!file.isDirectory()) { String relativePath=file.getAbsolutePath().substring(sourceDir.getAbsolutePath().length()); ZipEntry entry=createZipEntry(relativePath,isJar); output.putNextEntry(entry); FileInputStream fileInput=new FileInputStream(file); try { transfer(fileInput,output); } finally { Util.safeClose(fileInput); output.closeEntry(); } } } } finally { Util.safeClose(output); } }
Example 45
From project eclipse-integration-cloudfoundry, under directory /org.cloudfoundry.ide.eclipse.server.core/src/org/cloudfoundry/ide/eclipse/internal/server/core/.
Source file: CloudUtil.java

public static IStatus[] publishZip(List<IModuleResource> allResources,File tempFile,Set<IModuleResource> filterInFiles,IProgressMonitor monitor){ monitor=ProgressUtil.getMonitorFor(monitor); try { BufferedOutputStream bout=new BufferedOutputStream(new FileOutputStream(tempFile)); ZipOutputStream zout=new ZipOutputStream(bout); addZipEntries(zout,allResources,filterInFiles); zout.close(); } catch ( CoreException e) { return new IStatus[]{e.getStatus()}; } catch ( Exception e) { return new Status[]{new Status(IStatus.ERROR,ServerPlugin.PLUGIN_ID,0,NLS.bind(Messages.errorCreatingZipFile,tempFile.getName(),e.getLocalizedMessage()),e)}; } finally { if (tempFile != null && tempFile.exists()) tempFile.deleteOnExit(); } return EMPTY_STATUS; }
Example 46
From project eclipse.pde.build, under directory /org.eclipse.pde.build/src_ant/org/eclipse/pde/internal/build/publisher/.
Source file: BrandP2Task.java

private void publishBrandedArtifact(IArtifactRepository artifactRepo,IArtifactKey key){ ArtifactDescriptor descriptor=new ArtifactDescriptor(key); ZipOutputStream output=null; try { output=new ZipOutputStream(artifactRepo.getOutputStream(descriptor)); File root=new File(getRootFolder()); new File(root,"content.xml").delete(); new File(root,"artifacts.xml").delete(); new File(root,"content.jar").delete(); new File(root,"artifacts.jar").delete(); FileUtils.zip(output,root,Collections.EMPTY_SET,FileUtils.createRootPathComputer(root)); } catch ( ProvisionException e) { throw new BuildException(e.getMessage(),e); } catch ( IOException e) { throw new BuildException(e.getMessage(),e); } finally { Utils.close(output); } }
Example 47
From project enclojure, under directory /org-enclojure-ide/src/main/java/org/enclojure/ide/asm/optimizer/.
Source file: JarOptimizer.java

static void optimize(final File f) throws IOException { if (f.isDirectory()) { File[] files=f.listFiles(); for (int i=0; i < files.length; ++i) { optimize(files[i]); } } else if (f.getName().endsWith(".jar")) { File g=new File(f.getParentFile(),f.getName() + ".new"); ZipFile zf=new ZipFile(f); ZipOutputStream out=new ZipOutputStream(new FileOutputStream(g)); Enumeration e=zf.entries(); byte[] buf=new byte[10000]; while (e.hasMoreElements()) { ZipEntry ze=(ZipEntry)e.nextElement(); if (ze.isDirectory()) { continue; } out.putNextEntry(ze); if (ze.getName().endsWith(".class")) { ClassReader cr=new ClassReader(zf.getInputStream(ze)); cr.accept(new ClassVerifier(),0); } InputStream is=zf.getInputStream(ze); int n; do { n=is.read(buf,0,buf.length); if (n != -1) { out.write(buf,0,n); } } while (n != -1); out.closeEntry(); } out.close(); zf.close(); f.delete(); g.renameTo(f); } }
Example 48
From project Extlet6, under directory /liferay-6.0.5-patch/portal-impl/src/com/liferay/portal/deploy/hot/.
Source file: ExtHotDeployListener.java

private void zipWebInfJar(String zipName,File[] files) throws Exception { byte[] buffer=new byte[4096]; int bytesRead; ZipOutputStream out=new ZipOutputStream(new FileOutputStream(zipName)); try { for (int i=0; i < files.length; i++) { File f=files[i]; if (f.isDirectory()) { continue; } String fileName="WEB-INF/" + f.getName(); FileInputStream in=new FileInputStream(f); try { ZipEntry entry=new ZipEntry(fileName); out.putNextEntry(entry); while ((bytesRead=in.read(buffer)) != -1) { out.write(buffer,0,bytesRead); } } finally { in.close(); } } } finally { out.close(); } }
Example 49
From project fitnesse, under directory /src/fitnesse/wiki/zip/.
Source file: ZipFileVersionsController.java

public VersionInfo makeVersion(final FileSystemPage page,final PageData data){ final String dirPath=getFileSystemPath(page); final Set<File> filesToZip=getFilesToZip(dirPath); final VersionInfo version=makeVersionInfo(data); if (filesToZip.size() == 0) { return new VersionInfo("first_commit","",Clock.currentDate()); } ZipOutputStream zos=null; try { final String filename=makeVersionFileName(page,version.getName()); zos=new ZipOutputStream(new FileOutputStream(filename)); for ( File aFilesToZip : filesToZip) { addToZip(aFilesToZip,zos); } return new VersionInfo(version.getName()); } catch ( Throwable th) { throw new RuntimeException(th); } finally { try { if (zos != null) { zos.finish(); zos.close(); } } catch ( IOException e) { e.printStackTrace(); } } }
Example 50
From project freemind, under directory /freemind/accessories/plugins/.
Source file: ExportToOoWriter.java

public boolean exportToOoWriter(File file,StringWriter writer,String xslts) throws IOException { boolean resultValue=true; ZipOutputStream zipout=new ZipOutputStream(new FileOutputStream(file)); Result result=new StreamResult(zipout); StringTokenizer tokenizer=new StringTokenizer(xslts,","); while (tokenizer.hasMoreTokens()) { String token=tokenizer.nextToken(); String[] files=token.split("->"); if (files.length == 2) { ZipEntry entry=new ZipEntry(files[1]); zipout.putNextEntry(entry); if (files[0].endsWith(".xsl")) { logger.info("Transforming with xslt " + files[0] + " to file "+ files[1]); resultValue&=applyXsltFile(files[0],writer,result); } else { logger.info("Copying resource from " + files[0] + " to file "+ files[1]); resultValue&=copyFromResource(files[0],zipout); } zipout.closeEntry(); } } zipout.close(); return resultValue; }
Example 51
From project geronimo-xbean, under directory /xbean-finder/src/test/java/org/apache/xbean/finder/archive/.
Source file: Archives.java

public static File jarArchive(Map<String,String> entries,Class... classes) throws IOException { ClassLoader loader=Archives.class.getClassLoader(); File classpath=File.createTempFile("path with spaces",".jar"); ZipOutputStream out=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(classpath))); for ( Class clazz : classes) { String name=clazz.getName().replace('.','/') + ".class"; URL resource=loader.getResource(name); assertNotNull(resource); out.putNextEntry(new ZipEntry(name)); InputStream in=new BufferedInputStream(resource.openStream()); int i=-1; while ((i=in.read()) != -1) { out.write(i); } out.closeEntry(); } for ( Map.Entry<String,String> entry : entries.entrySet()) { out.putNextEntry(new ZipEntry(entry.getKey())); out.write(entry.getValue().getBytes()); } out.close(); return classpath; }
Example 52
From project gpslogger, under directory /GPSLogger/src/com/mendhak/gpslogger/senders/.
Source file: ZipHelper.java

public void Zip(){ try { BufferedInputStream origin; FileOutputStream dest=new FileOutputStream(zipFile); ZipOutputStream out=new ZipOutputStream(new BufferedOutputStream(dest)); byte data[]=new byte[BUFFER]; for ( String f : files) { FileInputStream fi=new FileInputStream(f); origin=new BufferedInputStream(fi,BUFFER); ZipEntry entry=new ZipEntry(f.substring(f.lastIndexOf("/") + 1)); out.putNextEntry(entry); int count; while ((count=origin.read(data,0,BUFFER)) != -1) { out.write(data,0,count); } out.closeEntry(); origin.close(); } out.close(); } catch ( Exception e) { e.printStackTrace(); } }
Example 53
From project GSM-Signal-Tracking-, under directory /gpstracker/src/nl/sogeti/android/gpstracker/actions/utils/.
Source file: XmlCreator.java

/** * Create a zip of the export directory based on the given filename * @param fileName The directory to be replaced by a zipped file of the same name * @param extension * @return full path of the build zip file * @throws IOException */ protected String bundlingMediaAndXml(String fileName,String extension) throws IOException { String zipFilePath; if (fileName.endsWith(".zip") || fileName.endsWith(extension)) { zipFilePath=Constants.getSdCardDirectory(mContext) + fileName; } else { zipFilePath=Constants.getSdCardDirectory(mContext) + fileName + extension; } String[] filenames=new File(mExportDirectoryPath).list(); byte[] buf=new byte[1024]; ZipOutputStream zos=null; try { zos=new ZipOutputStream(new FileOutputStream(zipFilePath)); for (int i=0; i < filenames.length; i++) { String entryFilePath=mExportDirectoryPath + "/" + filenames[i]; FileInputStream in=new FileInputStream(entryFilePath); zos.putNextEntry(new ZipEntry(filenames[i])); int len; while ((len=in.read(buf)) >= 0) { zos.write(buf,0,len); } zos.closeEntry(); in.close(); if (mProgressListener != null) { mProgressListener.increaseProgress((mProgressListener.getGoal() / 2) / filenames.length); } } } finally { if (zos != null) { zos.close(); } } deleteRecursive(new File(mExportDirectoryPath)); return zipFilePath; }
Example 54
From project hoop, under directory /hoop-server/src/test/java/com/cloudera/lib/io/.
Source file: TestIOUtils.java

@Test(dataProvider="zip") @TestDir public void zip(String base) throws IOException { File dir=getTestDir(); File subdir=new File(dir,"bar"); File subsubdir=new File(subdir,"woo"); File file=new File(subdir,"file"); Assert.assertTrue(subsubdir.mkdirs()); OutputStream os=new FileOutputStream(file); os.write('a'); os.close(); Set<String> contents=new HashSet<String>(); contents.add(base + "bar/woo/"); contents.add(base + "bar/file"); ByteArrayOutputStream baos=new ByteArrayOutputStream(); ZipOutputStream zos=new ZipOutputStream(baos); IOUtils.zipDir(dir,base,zos); ZipInputStream zis=new ZipInputStream(new ByteArrayInputStream(baos.toByteArray())); Set<String> zipContents=new HashSet<String>(); ZipEntry entry=zis.getNextEntry(); while (entry != null) { zipContents.add(entry.getName()); entry=zis.getNextEntry(); } Assert.assertEquals(zipContents,contents); }
Example 55
From project jentrata-msh, under directory /Commons/src/main/java/hk/hku/cecid/piazza/commons/util/.
Source file: Zip.java

/** * Compresses a set of files contained in a directory into a zip file. * @param toFile the zip file. * @param dir the directory which contains the files to be compressed. * @throws UtilitiesException if there is any error in the compression. */ public static void compress(File toFile,File dir) throws UtilitiesException { try { if (dir == null || !dir.exists() || !dir.isDirectory()) { throw new UtilitiesException("Invalid input directory: " + dir); } FileOutputStream fos=new FileOutputStream(toFile); ZipOutputStream outs=new ZipOutputStream(fos); FileSystem fs=new FileSystem(dir); Iterator allFiles=fs.getFiles(true).iterator(); while (allFiles.hasNext()) { File srcFile=(File)allFiles.next(); String filepath=srcFile.getAbsolutePath(); String dirpath=dir.getAbsolutePath(); String entryName=filepath.substring(dirpath.length() + 1).replace('\\','/'); ZipEntry zipEntry=new ZipEntry(entryName); zipEntry.setTime(srcFile.lastModified()); FileInputStream ins=new FileInputStream(srcFile); outs.putNextEntry(zipEntry); IOHandler.pipe(ins,outs); outs.closeEntry(); ins.close(); } outs.close(); } catch ( Exception e) { throw new UtilitiesException("Unable to compress zip file: " + toFile,e); } }
Example 56
/** * Saves the lesson to an {@link OutputStream} which contains an XMLdocument. Don't use this method directly. Use the {@link LessonProvider} instead.XML-Schema: <lesson> <deck> <card frontside="bla" backside="bla"/> .. </deck> .. </lesson> */ public static void saveAsXMLFile(File file,Lesson lesson) throws IOException, TransformerException, ParserConfigurationException { OutputStream out; ZipOutputStream zipOut=null; if (Settings.loadIsSaveCompressed()) { out=zipOut=new ZipOutputStream(new FileOutputStream(file)); zipOut.putNextEntry(new ZipEntry(LESSON_ZIP_ENTRY_NAME)); } else { out=new FileOutputStream(file); } try { Document document=DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); Element lessonTag=document.createElement(LESSON); document.appendChild(lessonTag); writeCategory(document,lessonTag,lesson.getRootCategory()); writeLearnHistory(document,lesson.getLearnHistory()); Transformer transformer=TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.ENCODING,"UTF-8"); transformer.setOutputProperty(OutputKeys.INDENT,"yes"); transformer.transform(new DOMSource(document),new StreamResult(out)); } finally { if (zipOut != null) zipOut.closeEntry(); else if (out != null) out.close(); } try { removeUnusedImagesFromRepository(lesson); if (zipOut == null) writeImageRepositoryToDisk(new File(file.getParent())); else writeImageRepositoryToZip(zipOut); } finally { if (zipOut != null) zipOut.close(); } }
Example 57
From project jsfunit, under directory /jboss-jsfunit-ant/src/main/java/org/jboss/jsfunit/ant/.
Source file: Utils.java

/** * Zips a directory. If the directory is an exploded archive, then don't add the directory itself to the zipped file * @param srcDirectory the directory to zip * @param destFile the newly created zip file * @param isArchive true if the srcDirectory is a exploded archive * @throws Exception if an error occured during the zip */ public static void zip(File srcDirectory,File destFile,Boolean isArchive) throws Exception { if (destFile.exists()) { throw new Exception("The destFile [ + " + destFile + " already exists, cannot zip to an already existing file"); } OutputStream os=new FileOutputStream(destFile); ZipOutputStream zos=new ZipOutputStream(os); try { if (isArchive) { archive("",srcDirectory,zos); } else { zip("",srcDirectory,zos); } } finally { zos.close(); os.close(); } }
Example 58
From project JSimpleTracker, under directory /libs/apache-log4j-1.2.16/apache-log4j-1.2.16/tests/src/java/org/apache/log4j/xml/.
Source file: DOMTestCase.java

/** * Test for bug 47465. configure(URL) did not close opened JarURLConnection. * @throws IOException if IOException creating properties jar. */ public void testJarURL() throws IOException { File input=new File("input/xml/defaultInit.xml"); System.out.println(input.getAbsolutePath()); InputStream is=new FileInputStream(input); File dir=new File("output"); dir.mkdirs(); File file=new File("output/xml.jar"); ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(file)); zos.putNextEntry(new ZipEntry("log4j.xml")); int len; byte[] buf=new byte[1024]; while ((len=is.read(buf)) > 0) { zos.write(buf,0,len); } zos.closeEntry(); zos.close(); URL url=new URL("jar:" + file.toURL() + "!/log4j.xml"); DOMConfigurator.configure(url); assertTrue(file.delete()); assertFalse(file.exists()); }
Example 59
From project karaf, under directory /diagnostic/core/src/main/java/org/apache/karaf/diagnostic/core/common/.
Source file: ZipDumpDestination.java

/** * Creates new dump in given file (zip archive). * @param file Destination file. */ public ZipDumpDestination(File file){ try { outputStream=new ZipOutputStream(new FileOutputStream(file)); } catch ( FileNotFoundException e) { throw new RuntimeException("Unable to create dump destination",e); } }
Example 60
From project lyo.testsuite, under directory /org.eclipse.lyo.testsuite.server/src/main/java/org/eclipse/lyo/testsuite/tools/.
Source file: RAMConfigTool.java

private static void writeConfig(String location,boolean createZip) throws IOException { File directory=new File(location); if (!directory.exists()) directory.mkdirs(); if (createZip) { String zipFileName=properties.getProperty("outputFileName"); if (zipFileName == null) zipFileName="config.zip"; ZipOutputStream zip=new ZipOutputStream(new FileOutputStream(location + zipFileName)); addToZip(zip,"xml/","create","xml",xmlCreateTemplate); addToZip(zip,"xml/","createArtifact","xml",xmlArtifactTemplate); addToZip(zip,"xml/","createCategory","xml",xmlCategoryTemplate); addToZip(zip,"xml/","createRelationship","xml",xmlRelationshipTemplate); addToZip(zip,"xml/","update","xml",xmlUpdateTemplate); addToZip(zip,"json/","create","json",jsonCreateTemplate); addToZip(zip,"json/","createArtifact","json",jsonArtifactTemplate); addToZip(zip,"json/","createCategory","json",jsonCategoryTemplate); addToZip(zip,"json/","createRelationship","json",jsonRelationshipTemplate); addToZip(zip,"json/","update","json",jsonUpdateTemplate); addToZip(zip,"","setup","properties",setupPropertyTemplate); addToZip(zip,"","testArtifact","properties",testArtifactTemplate); zip.close(); } else { directory=new File(location + "xml/"); if (!directory.exists()) directory.mkdirs(); directory=new File(location + "json/"); if (!directory.exists()) directory.mkdirs(); writeFile(location + "xml/create.xml",xmlCreateTemplate); writeFile(location + "xml/createArtifact.xml",xmlArtifactTemplate); writeFile(location + "xml/createCategory.xml",xmlCategoryTemplate); writeFile(location + "xml/createRelationship.xml",xmlRelationshipTemplate); writeFile(location + "xml/update.xml",xmlUpdateTemplate); writeFile(location + "json/create.json",jsonCreateTemplate); writeFile(location + "json/createArtifact.json",jsonArtifactTemplate); writeFile(location + "json/createCategory.json",jsonCategoryTemplate); writeFile(location + "json/createRelationship.json",jsonRelationshipTemplate); writeFile(location + "json/update.json",jsonUpdateTemplate); writeFile(location + "setup.properties",setupPropertyTemplate); writeFile(location + "testArtifact.txt",testArtifactTemplate); } }
Example 61
From project maven-android-plugin, under directory /src/main/java/com/jayway/maven/plugins/android/phase09package/.
Source file: ApkMojo.java

private void addMetaInf(File outputFile,ArrayList<File> jarFiles) throws IOException { File tmp=File.createTempFile(outputFile.getName(),".add",outputFile.getParentFile()); FileOutputStream fos=new FileOutputStream(tmp); ZipOutputStream zos=new ZipOutputStream(fos); Set<String> entries=new HashSet<String>(); updateWithMetaInf(zos,outputFile,entries,false); for ( File f : jarFiles) { updateWithMetaInf(zos,f,entries,true); } zos.close(); outputFile.delete(); if (!tmp.renameTo(outputFile)) { throw new IOException(String.format("Cannot rename %s to %s",tmp,outputFile.getName())); } }
Example 62
From project maven-shared, under directory /maven-jarsigner/src/main/java/org/apache/maven/shared/jarsigner/.
Source file: JarSignerUtil.java

/** * Removes any existing signatures from the specified JAR file. We will stream from the input JAR directly to the output JAR to retain as much metadata from the original JAR as possible. * @param jarFile The JAR file to unsign, must not be <code>null</code>. * @throws java.io.IOException */ public static void unsignArchive(File jarFile) throws IOException { File unsignedFile=new File(jarFile.getAbsolutePath() + ".unsigned"); ZipInputStream zis=null; ZipOutputStream zos=null; try { zis=new ZipInputStream(new BufferedInputStream(new FileInputStream(jarFile))); zos=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(unsignedFile))); for (ZipEntry ze=zis.getNextEntry(); ze != null; ze=zis.getNextEntry()) { if (isSignatureFile(ze.getName())) { continue; } zos.putNextEntry(ze); IOUtil.copy(zis,zos); } } finally { IOUtil.close(zis); IOUtil.close(zos); } FileUtils.rename(unsignedFile,jarFile); }
Example 63
From project Metamorphosis, under directory /metamorphosis-server/src/main/java/com/taobao/metamorphosis/server/store/.
Source file: ArchiveDeletePolicy.java

/** * ?????? */ @Override public void process(File file){ String name=file.getName(); if (this.compress) { String newName=name.concat(".zip"); final File newFile=new File(file.getParent(),newName); FileOutputStream out=null; ZipOutputStream zipOut=null; FileInputStream in=null; try { out=new FileOutputStream(newFile); zipOut=new ZipOutputStream(out); ZipEntry zipEntry=new ZipEntry(name); zipOut.putNextEntry(zipEntry); in=new FileInputStream(file); byte[] buf=new byte[8192]; int len=-1; while ((len=in.read(buf)) != -1) { zipOut.write(buf,0,len); } zipOut.closeEntry(); zipOut.close(); } catch ( IOException e) { log.error("Compress file " + file.getAbsolutePath() + " failed",e); } finally { this.close(zipOut); this.close(out); this.close(in); file.delete(); } } else { String newName=name.concat(".arc"); final File newFile=new File(file.getParent(),newName); file.renameTo(newFile); } }
Example 64
From project Mura-Tools-for-Eclipse-Core, under directory /src/com/muratools/eclipse/wizard/buildPlugin/.
Source file: BuildPluginWizard.java

@Override public boolean performFinish(){ ZipUtil zip=new ZipUtil(getTargetDirectory()); plugin.setTargetDirectory(getTargetDirectory()); getConfig().setVersion(page.getVersion()); plugin.saveConfigXML(getConfig()); try { ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(page.getContainerPath() + "/" + page.getFileName())); zip.zipDirectory(getTargetDirectory(),zos); zos.close(); } catch ( Exception e) { getConfig().setVersion(decrementBuildNumber(getConfig().getVersion())); plugin.saveConfigXML(getConfig()); } refreshContainer(); return true; }
Example 65
From project mylyn.context, under directory /org.eclipse.mylyn.context.core/src/org/eclipse/mylyn/internal/context/core/.
Source file: InteractionContextExternalizer.java

/** * Public for testing. * @throws IOException if writing of context fails */ public void writeContextToXml(IInteractionContext context,File file,IInteractionContextWriter writer) throws IOException { if (context.getInteractionHistory().isEmpty()) { return; } FileOutputStream fileOutputStream=new FileOutputStream(file); try { ZipOutputStream outputStream=new ZipOutputStream(fileOutputStream); try { writeContext(context,outputStream,writer); } finally { outputStream.close(); } } finally { fileOutputStream.close(); } }
Example 66
From project ndg, under directory /ndg-web-server/src/br/org/indt/ndg/client/.
Source file: Service.java

private void zipSurvey(String surveyId,byte[] fileContent,String fileType){ final String SURVEY="survey"; FileOutputStream arqExport; try { if (fileType.equals(XLS)) { arqExport=new FileOutputStream(surveyId + File.separator + SURVEY+ surveyId+ XLS); arqExport.write(fileContent); arqExport.close(); } else if (fileType.equals(CSV)) { arqExport=new FileOutputStream(surveyId + File.separator + SURVEY+ surveyId+ CSV); arqExport.write(fileContent); arqExport.close(); } ZipOutputStream zos=new ZipOutputStream(new FileOutputStream(SURVEY + surveyId + ZIP)); zipDir(surveyId,zos); zos.close(); } catch ( Exception e) { e.printStackTrace(); } }
Example 67
From project No-Pain-No-Game, under directory /src/edu/ucla/cs/nopainnogame/weightchart/.
Source file: FileCommands.java

private void exportOds(File file,Cursor cursor){ try { ZipOutputStream output=new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file))); OutputStreamWriter writer=new OutputStreamWriter(output); output.putNextEntry(new ZipEntry("META-INF/manifest.xml")); writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" " + "standalone=\"yes\"?><manifest:manifest xmlns:manifest=" + "\"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0\">"+ "<manifest:file-entry manifest:media-type=\""+ "application/vnd.oasis.opendocument.spreadsheet\" "+ "manifest:full-path=\"/\"></manifest:file-entry>"+ "</manifest:manifest>"); writer.flush(); output.putNextEntry(new ZipEntry("content.xml")); BufferedWriter bufferedWriter=new BufferedWriter(writer); bufferedWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<office:document-content " + "xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" "+ "xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" "+ "xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" "+ "xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" "+ "xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\">"+ "<office:automatic-styles>"+ "<style:style style:family=\"table-column\" style:name=\"co1\">"+ "<style:table-column-properties style:column-width=\"3.5cm\"/>"+ "</style:style>"+ "<number:date-style number:automatic-order=\"true\" style:name=\"N1\">"+ "<number:year number:style=\"long\"/><number:text>-</number:text>"+ "<number:month number:style=\"long\"/><number:text>-</number:text>"+ "<number:day number:style=\"long\"/><number:text> </number:text>"+ "<number:hours number:style=\"long\"/><number:text>:</number:text>"+ "<number:minutes number:style=\"long\"/><number:text>:</number:text>"+ "<number:seconds number:style=\"long\"/></number:date-style>"+ "<number:number-style style:name=\"N2\"><number:number "+ "number:decimal-places=\"1\" number:min-integer-digits=\"1\"/>"+ "</number:number-style>"+ "<style:style style:name=\"ce1\" style:data-style-name=\"N1\" "+ "style:family=\"table-cell\"/>"+ "<style:style style:name=\"ce2\" style:data-style-name=\"N2\" "+ "style:family=\"table-cell\"/>"+ "</office:automatic-styles>"+ "<office:body><office:spreadsheet><table:table table:name=\"weight\">"+ "<table:table-column table:default-cell-style-name=\"ce1\" "+ "table:style-name=\"co1\"/>"+ "<table:table-column table:default-cell-style-name=\"ce2\"/>"); SimpleDateFormat format1=new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); SimpleDateFormat format2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); while (cursor.moveToNext()) { bufferedWriter.write("<table:table-row><table:table-cell " + "office:value-type=\"date\" office:date-value=\""); Date date=new Date(1000L * cursor.getInt(1)); bufferedWriter.write(format1.format(date)); bufferedWriter.write("\"><text:p>"); bufferedWriter.write(format2.format(date)); bufferedWriter.write("</text:p></table:table-cell>" + "<table:table-cell office:value-type=\"float\" office:value=\""); String weight="" + cursor.getInt(0) / 10.; bufferedWriter.write(weight); bufferedWriter.write("\"><text:p>"); bufferedWriter.write(weight); bufferedWriter.write("</text:p></table:table-cell></table:table-row>"); } bufferedWriter.write("</table:table></office:spreadsheet></office:body>" + "</office:document-content>"); bufferedWriter.close(); } catch ( IOException e) { showMessageDialog(R.string.failed_save_file,file); return; } sendFile(file,"application/vnd.oasis.opendocument.spreadsheet"); }
Example 68
From project nuxeo-jsf, under directory /nuxeo-platform-webapp-base/src/main/java/org/nuxeo/ecm/webapp/clipboard/.
Source file: DocumentListZipExporter.java

public File exportWorklistAsZip(List<DocumentModel> documents,CoreSession documentManager,boolean exportAllBlobs) throws ClientException, IOException { StringBuilder blobList=new StringBuilder(); File tmpFile=File.createTempFile("NX-BigZipFile-",".zip"); tmpFile.deleteOnExit(); FileOutputStream fout=new FileOutputStream(tmpFile); ZipOutputStream out=new ZipOutputStream(fout); out.setMethod(ZipOutputStream.DEFLATED); out.setLevel(9); byte[] data=new byte[BUFFER]; for ( DocumentModel doc : documents) { if (doc.getSessionId() == null) { doc=documentManager.getDocument(doc.getRef()); } if (LifeCycleConstants.DELETED_STATE.equals(doc.getCurrentLifeCycleState())) { continue; } BlobHolder bh=doc.getAdapter(BlobHolder.class); if (doc.isFolder() && !isEmptyFolder(doc,documentManager)) { addFolderToZip("",out,doc,data,documentManager,blobList,exportAllBlobs); } else if (bh != null) { addBlobHolderToZip("",out,doc,data,blobList,bh,exportAllBlobs); } } if (blobList.length() > 1) { addSummaryToZip(out,data,blobList); } try { out.close(); fout.close(); } catch ( ZipException e) { return null; } return tmpFile; }
Example 69
From project onebusaway-gtfs-modules, under directory /onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/services/.
Source file: MockGtfs.java

private void updateZipFile(){ try { if (_path.exists()) { _path.delete(); } ZipOutputStream out=new ZipOutputStream(new FileOutputStream(_path)); for ( Map.Entry<String,byte[]> entry : _contentByFileName.entrySet()) { String fileName=entry.getKey(); byte[] content=entry.getValue(); ZipEntry zipEntry=new ZipEntry(fileName); out.putNextEntry(zipEntry); out.write(content); out.closeEntry(); } out.close(); } catch ( IOException ex) { throw new IllegalStateException(ex); } }
Example 70
From project opennlp, under directory /opennlp-tools/src/main/java/opennlp/tools/util/model/.
Source file: BaseModel.java

/** * Serializes the model to the given {@link OutputStream}. * @param out stream to write the model to * @throws IOException */ @SuppressWarnings("unchecked") public final void serialize(OutputStream out) throws IOException { if (!subclassSerializersInitiated) { throw new IllegalStateException("The method BaseModel.loadArtifactSerializers() was not called by BaseModel subclass constructor."); } ZipOutputStream zip=new ZipOutputStream(out); for ( String name : artifactMap.keySet()) { zip.putNextEntry(new ZipEntry(name)); ArtifactSerializer serializer=getArtifactSerializer(name); if (serializer == null) { throw new IllegalStateException("Missing serializer for " + name); } serializer.serialize(artifactMap.get(name),zip); zip.closeEntry(); } zip.finish(); zip.flush(); }
Example 71
From project org.openscada.external, under directory /org.openscada.external.jOpenDocument/src/org/jopendocument/util/.
Source file: Zip.java

private synchronized ZipOutputStream getOutStream(){ if (this.zos == null) { this.zos=new ZipOutputStream(this.outstream); } return this.zos; }
Example 72
From project org.openscada.orilla, under directory /org.openscada.ca.ui/src/org/openscada/ca/ui/util/.
Source file: OscarWriter.java

/** * Perform the write operation <p> The stream is closed. </p> * @param targetStream target stream to write to * @throws IOException if an IO error occurs */ public void write(final OutputStream targetStream) throws IOException { final ZipOutputStream zout=new ZipOutputStream(targetStream); try { ZipEntry entry; entry=new ZipEntry("data.json"); zout.putNextEntry(entry); writeData(this.data,zout); zout.closeEntry(); if (this.ignoreData != null && !this.ignoreData.isEmpty()) { entry=new ZipEntry("ignoreFields.json"); zout.putNextEntry(entry); writeIgnoreData(this.ignoreData,zout); zout.closeEntry(); } } finally { zout.close(); } }
Example 73
From project org.ops4j.pax.logging, under directory /pax-logging-samples/fragment/src/main/java/org/ops4j/pax/logging/extender/.
Source file: ZipRollingFileAppender.java

boolean archiveFile(File logFile){ FileOutputStream fOut; ZipOutputStream zOut; try { fOut=new FileOutputStream(logFile.getPath() + ".zip"); zOut=new ZipOutputStream(fOut); FileInputStream fIn=new FileInputStream(logFile); BufferedInputStream bIn=new BufferedInputStream(fIn); ZipEntry entry=new ZipEntry(logFile.getCanonicalFile().getName()); zOut.putNextEntry(entry); byte[] barray=new byte[1024]; int bytes; while ((bytes=bIn.read(barray,0,1024)) > -1) { zOut.write(barray,0,bytes); } zOut.flush(); zOut.close(); fOut.close(); return true; } catch ( IOException ioE) { return false; } }
Example 74
From project org.ops4j.pax.runner, under directory /pax-runner-platform/src/main/java/org/ops4j/pax/runner/platform/.
Source file: ZipJavaRunner.java

/** * {@inheritDoc} */ public void exec(final String[] vmOptions,final String[] classpath,final String mainClass,final String[] programOptions,final String javaHome,final File workingDir,String[] environmentVariables) throws PlatformException { super.exec(vmOptions,classpath,mainClass,programOptions,javaHome,workingDir,environmentVariables); LOG.info("Now writing distribution zip.."); ZipOutputStream dest=null; try { File destFile=new File("paxrunner-" + workingDir.getName() + ".zip"); dest=new ZipOutputStream(new FileOutputStream(destFile)); int baseIdx=workingDir.getCanonicalFile().getParentFile().getCanonicalPath().length() + 1; add(baseIdx,workingDir,dest); workingDir.deleteOnExit(); LOG.info("Distribution written: " + destFile.getName()); } catch ( FileNotFoundException e) { throw new PlatformException(e.getMessage(),e); } catch ( IOException e) { throw new PlatformException(e.getMessage(),e); } finally { try { if (dest != null) { dest.close(); } } catch ( IOException e) { } } }
Example 75
From project orion.server, under directory /bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/xfer/.
Source file: ClientExport.java

public void doExport(HttpServletRequest req,HttpServletResponse resp) throws IOException, ServletException { IFileStore source=NewFileServlet.getFileStore(sourcePath); try { if (source.fetchInfo().isDirectory() && source.childNames(EFS.NONE,null).length == 0) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED,"You cannot export an empty folder"); return; } ZipOutputStream zout=new ZipOutputStream(resp.getOutputStream()); write(source,Path.EMPTY,zout); zout.finish(); } catch ( CoreException e) { throw new ServletException(e); } }
Example 76
From project pangool, under directory /core/src/main/java/com/datasalt/pangool/solr/.
Source file: SolrRecordWriter.java

private void packZipFile() throws IOException { FSDataOutputStream out=null; ZipOutputStream zos=null; int zipCount=0; LOG.info("Packing zip file for " + perm); try { out=fs.create(perm,false); zos=new ZipOutputStream(out); String name=perm.getName().replaceAll(".zip$",""); LOG.info("adding index directory" + temp); zipCount=zipDirectory(conf,zos,name,temp.toString(),temp); } catch ( Throwable ohFoo) { LOG.error("packZipFile exception",ohFoo); if (ohFoo instanceof RuntimeException) { throw (RuntimeException)ohFoo; } if (ohFoo instanceof IOException) { throw (IOException)ohFoo; } throw new IOException(ohFoo); } finally { if (zos != null) { if (zipCount == 0) { LOG.error("No entries written to zip file " + perm); fs.delete(perm,false); } else { LOG.info(String.format("Wrote %d items to %s for %s",zipCount,perm,temp)); zos.close(); } } } }
Example 77
From project pepe, under directory /pepe/src/edu/stanford/pepe/.
Source file: JREInstrumenter.java

public static void main(String[] args) throws IOException { ZipInputStream is=new ZipInputStream(new FileInputStream(INPUT)); ZipEntry je; ZipOutputStream os=new ZipOutputStream(new FileOutputStream(OUTPUT)); while ((je=is.getNextEntry()) != null) { byte[] byteArray=read(is); if (je.getName().endsWith(".class")) { ClassNode cn=new ClassNode(); ClassReader cr=new ClassReader(byteArray); cr.accept(cn,0); if (InstrumentationPolicy.isTypeInstrumentable(cn.name) || InstrumentationPolicy.isSpecialJavaClass(cn.name)) { byteArray=PepeAgent.instrumentClass(cn); } else { System.out.println("Skipping " + cn.name); } } JarEntry newJarEntry=new JarEntry(je.getName()); os.putNextEntry(newJarEntry); os.write(byteArray); } is.close(); os.close(); }
Example 78
From project PIE, under directory /R2/pie-runtime/src/main/java/com/pieframework/runtime/utils/.
Source file: Zipper.java

public static void zip(String zipFile,Map<String,File> flist){ byte[] buf=new byte[1024]; try { ZipOutputStream out=new ZipOutputStream(new FileOutputStream(zipFile)); for ( String url : flist.keySet()) { FileInputStream in=new FileInputStream(flist.get(url).getPath()); out.putNextEntry(new ZipEntry(url)); int len; while ((len=in.read(buf)) > 0) { out.write(buf,0,len); } out.closeEntry(); in.close(); } out.close(); } catch ( Exception e) { throw new RuntimeException("Encountered errors zipping file " + zipFile,e); } }
Example 79
From project platform_1, under directory /component/organization/src/main/java/org/exoplatform/platform/organization/injector/.
Source file: JMXDataInjector.java

/** * extract Organization Data to a zip file * @param filePath exported file path * @throws Exception */ @Managed @ManagedDescription("extract Organization Data to a zip file") @Impact(ImpactType.READ) public void extractData(@ManagedDescription("exported file path") @ManagedName("filePath") String filePath) throws Exception { if (filePath == null || filePath.isEmpty() || !filePath.endsWith(".zip")) { throw new IllegalArgumentException(filePath + " have to point into a zip file."); } File targetFile=new File(filePath); if (targetFile.exists()) { throw new IllegalArgumentException(filePath + " already exists."); } LOG.info("Extracting Organization model data to : " + filePath); OutputStream out=new FileOutputStream(filePath); ZipOutputStream zos=new ZipOutputStream(out); dataInjectorService.writeProfiles(zos); dataInjectorService.writeUsers(zos); dataInjectorService.writeOrganizationModelData(zos); zos.close(); LOG.info("Organization model data successfully exported."); }
Example 80
From project android_packages_apps_FileManager, under directory /src/org/openintents/filemanager/util/.
Source file: CompressManager.java

@Override protected void onPreExecute(){ FileOutputStream out=null; progressDialog=new ProgressDialog(activity); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage(activity.getResources().getString(R.string.compressing)); progressDialog.show(); progressDialog.setProgress(0); try { out=new FileOutputStream(new File(fileOut)); zos=new ZipOutputStream(new BufferedOutputStream(out)); } catch ( FileNotFoundException e) { Log.e(TAG,"error while creating ZipOutputStream"); } }
Example 81
From project c24-spring, under directory /c24-spring-batch/src/main/java/biz/c24/io/spring/batch/writer/source/.
Source file: ZipFileWriterSource.java

@Override public void initialise(StepExecution stepExecution){ String fileName=resource != null ? resource.getPath() : stepExecution.getJobParameters().getString("output.file"); if (fileName.startsWith("file://")) { fileName=fileName.substring("file://".length()); } int tailStarts=fileName.lastIndexOf(pathSepString) + 1; int tailEnds=fileName.lastIndexOf('.'); if (tailStarts < 0) { tailStarts=0; } if (tailEnds < 0) { tailEnds=fileName.length(); } String tailName=fileName.substring(tailStarts,tailEnds); try { FileOutputStream fileStream=new FileOutputStream(fileName); zipStream=new ZipOutputStream(fileStream); zipStream.putNextEntry(new ZipEntry(tailName)); outputWriter=new OutputStreamWriter(zipStream,getEncoding()); } catch ( IOException ioEx) { throw new RuntimeException(ioEx); } }
Example 82
From project Catroid-maven-playground, under directory /src/main/java/at/tugraz/ist/catroid/utils/.
Source file: UtilZip.java

public static boolean writeToZipFile(String[] filePaths,String zipFile){ try { FileOutputStream fileOutputStream=new FileOutputStream(zipFile); zipOutputStream=new ZipOutputStream(fileOutputStream); zipOutputStream.setLevel(QUICKEST_COMPRESSION); for ( String filePath : filePaths) { File file=new File(filePath); if (file.isDirectory()) { writeDirToZip(file,file.getName() + "/"); } else { writeFileToZip(file,""); } } zipOutputStream.close(); return true; } catch ( IOException e) { e.printStackTrace(); } return false; }
Example 83
From project filemanager, under directory /FileManager/src/org/openintents/filemanager/util/.
Source file: CompressManager.java

@Override protected void onPreExecute(){ FileOutputStream out=null; progressDialog=new ProgressDialog(mContext); progressDialog.setCancelable(false); progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); progressDialog.setMessage(mContext.getString(R.string.compressing)); progressDialog.show(); progressDialog.setProgress(0); try { out=new FileOutputStream(new File(fileOut)); zos=new ZipOutputStream(new BufferedOutputStream(out)); } catch ( FileNotFoundException e) { Log.e(TAG,"error while creating ZipOutputStream"); } }
Example 84
From project JGit, under directory /org.spearce.jgit.pgm/src/org/spearce/jgit/pgm/build/.
Source file: JarLinkUtil.java

private void run() throws IOException { for ( final File src : includes) { if (src.isFile()) scanJar(src); else scanDirectory(src,src,""); } for ( final Map.Entry<String,String> e : files.entrySet()) chosenSources.put(e.getKey(),new File(e.getValue())); creationTime=System.currentTimeMillis(); zos=new ZipOutputStream(System.out); zos.setLevel(9); for ( final File src : includes) { if (src.isFile()) appendJar(src); else appendDirectory(src,src,""); } for ( final String name : files.keySet()) appendFile(chosenSources.get(name),name); zos.close(); }
Example 85
public void zipTo(OutputStream output){ try { if (!fs.exists(directoryPath) && !fs.isDirectory(directoryPath)) throw new LimelightException(directoryPath + " is not a valid directory"); zipOutput=new ZipOutputStream(output); zipDirectory(directoryPath); zipOutput.finish(); zipOutput.close(); } catch ( LimelightException e) { throw e; } catch ( Exception e) { throw new LimelightException(e); } }
Example 86
private JarOutputStream openJar() throws IOException { FileUtils.validateDirectory(jarFile.getParentFile()); if (jarFile.exists() && !jarFile.canWrite() && !jarFile.delete()) { throw new BuildException("Can not recreate: '" + jarFile + "'."); } final FileOutputStream os=new FileOutputStream(jarFile); final JarOutputStream jarOutputStream=new JarOutputStream(os); jarOutputStream.setMethod(doCompress ? ZipOutputStream.DEFLATED : ZipOutputStream.STORED); jarOutputStream.setLevel(level); return jarOutputStream; }
Example 87
From project FML, under directory /common/cpw/mods/fml/common/asm/transformers/.
Source file: MCPMerger.java

private static void copyClass(ZipFile inJar,ZipEntry entry,ZipOutputStream outJar,ZipOutputStream outJar2,boolean isClientOnly) throws IOException { ClassReader reader=new ClassReader(readEntry(inJar,entry)); ClassNode classNode=new ClassNode(); reader.accept(classNode,0); if (!classNode.name.equals("ayn")) { if (classNode.visibleAnnotations == null) classNode.visibleAnnotations=new ArrayList<AnnotationNode>(); classNode.visibleAnnotations.add(getSideAnn(isClientOnly)); } ClassWriter writer=new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); byte[] data=writer.toByteArray(); ZipEntry newEntry=new ZipEntry(entry.getName()); if (outJar != null) { outJar.putNextEntry(newEntry); outJar.write(data); } if (outJar2 != null) { outJar2.putNextEntry(newEntry); outJar2.write(data); } }
Example 88
From project ISAcreator, under directory /src/main/java/org/isatools/isacreator/archiveoutput/.
Source file: ArchiveOutputUtil.java

public void zipDir(String sourceDir,File dirToZip,ZipOutputStream zos,byte[] buffer){ try { String[] dirList=dirToZip.list(); int bytesIn; for ( String aDirList : dirList) { File f=new File(dirToZip,aDirList); if (!f.getName().startsWith(".")) { if (f.isDirectory()) { zipDir(sourceDir,f,zos,buffer); continue; } FileInputStream fis=new FileInputStream(f); zos.putNextEntry(new ZipEntry(getPathForZip(sourceDir,f.getPath()))); statistics.addToNumberOfFiles(1); statistics.addToUncompressedSize(f.length()); while ((bytesIn=fis.read(buffer)) != -1) { zos.write(buffer,0,bytesIn); } fis.close(); } } } catch ( Exception e) { log.error(e.getMessage()); } }
Example 89
From project mididuino, under directory /editor/app/src/processing/app/.
Source file: Sketch.java

protected void addManifest(ZipOutputStream zos) throws IOException { ZipEntry entry=new ZipEntry("META-INF/MANIFEST.MF"); zos.putNextEntry(entry); String contents="Manifest-Version: 1.0\n" + "Created-By: Processing " + Base.VERSION_NAME + "\n"+ "Main-Class: "+ name+ "\n"; zos.write(contents.getBytes()); zos.closeEntry(); }
Example 90
From project org.eclipse.scout.builder, under directory /org.eclipse.scout.releng.ant/src/org/eclipse/scout/releng/ant/archive/.
Source file: CreateDropInZip.java

private void addFile(ZipOutputStream zipStream,File fileToAdd,String relativeFileName) throws IOException { BufferedInputStream in=null; try { ZipEntry entry=new ZipEntry(relativeFileName); entry.setTime(fileToAdd.lastModified()); zipStream.putNextEntry(entry); in=new BufferedInputStream(new FileInputStream(fileToAdd)); byte[] buffer=new byte[20480]; while (true) { int count=in.read(buffer); if (count == -1) break; zipStream.write(buffer,0,count); } zipStream.closeEntry(); } finally { if (in != null) { in.close(); } } }