List of usage examples for java.util.zip ZipInputStream getNextEntry
public ZipEntry getNextEntry() throws IOException
From source file:localization.split.java
public static Vector<String> readzipfile(String filepath) { Vector<String> v = new Vector<String>(); byte[] buffer = new byte[1024]; String outputFolder = filepath.substring(0, filepath.lastIndexOf(".")); System.out.println(outputFolder); try {/* w w w .j av a 2 s .co m*/ File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(filepath)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + "\\" + fileName); v.addElement(newFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (Exception e) { } return v; }
From source file:ZipFileIO.java
/** * Return the first directory of this archive. This is needed to determine * the plugin directory./*from w w w . j a v a 2 s.c om*/ * * @param zipFile * @return <class>File</class> containing the first entry of this archive */ public static File getFirstFile(File zipFile) throws IOException { ZipInputStream in = null; try { // Open the ZIP file in = new ZipInputStream(new FileInputStream(zipFile)); // Get the first entry ZipEntry entry = null; while ((entry = in.getNextEntry()) != null) { String outFilename = entry.getName(); if (entry.isDirectory()) { return new File(outFilename); } } } finally { if (in != null) { // Close the stream in.close(); } } return null; }
From source file:be.fedict.eid.applet.service.signer.odf.ODFUtil.java
/** * Read the zipped data in the ODF package and return the inputstream for a * given file / zip entry/*from www.j a va2s . c o m*/ * * @param inputStream * @param uri * @return inputstream for the file / zip entry * @throws IOException */ public static InputStream findDataInputStream(InputStream inputStream, String uri) throws IOException { ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (zipEntry.getName().equals(uri)) { return zipInputStream; } } return null; }
From source file:be.fedict.eid.applet.service.signer.odf.ODFUtil.java
/** * Get a list of all the files / zip entries in an ODF package * //from w w w . ja v a 2 s. co m * @param odfInputStream * @return * @throws IOException */ public static List getZipEntriesAsList(InputStream odfInputStream) throws IOException { ArrayList list = new ArrayList(); ZipInputStream odfZipInputStream = new ZipInputStream(odfInputStream); ZipEntry zipEntry; while (null != (zipEntry = odfZipInputStream.getNextEntry())) { list.add(zipEntry.getName()); } return list; }
From source file:Main.java
public static boolean unzip(InputStream inputStream, String dest, boolean replaceIfExists) { final int BUFFER_SIZE = 4096; BufferedOutputStream bufferedOutputStream = null; boolean succeed = true; try {/*from w w w. j a v a 2 s . c om*/ ZipInputStream zipInputStream = new ZipInputStream(new BufferedInputStream(inputStream)); ZipEntry zipEntry; while ((zipEntry = zipInputStream.getNextEntry()) != null) { String zipEntryName = zipEntry.getName(); // if(!zipEntry.isDirectory()) { // File fil = new File(dest + zipEntryName); // fil.getParent() // } // file exists ? delete ? File file2 = new File(dest + zipEntryName); if (file2.exists()) { if (replaceIfExists) { try { boolean b = deleteDir(file2); if (!b) { Log.e("Haggle", "Unzip failed to delete " + dest + zipEntryName); } else { Log.d("Haggle", "Unzip deleted " + dest + zipEntryName); } } catch (Exception e) { Log.e("Haggle", "Unzip failed to delete " + dest + zipEntryName, e); } } } // extract File file = new File(dest + zipEntryName); if (file.exists()) { } else { if (zipEntry.isDirectory()) { file.mkdirs(); chmod(file, 0755); } else { // create parent file folder if not exists yet if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); chmod(file.getParentFile(), 0755); } byte buffer[] = new byte[BUFFER_SIZE]; bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE); int count; while ((count = zipInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) { bufferedOutputStream.write(buffer, 0, count); } bufferedOutputStream.flush(); bufferedOutputStream.close(); } } // enable standalone python if (file.getName().endsWith(".so") || file.getName().endsWith(".xml") || file.getName().endsWith(".py") || file.getName().endsWith(".pyc") || file.getName().endsWith(".pyo")) { chmod(file, 0755); } Log.d("Haggle", "Unzip extracted " + dest + zipEntryName); } zipInputStream.close(); } catch (FileNotFoundException e) { Log.e("Haggle", "Unzip error, file not found", e); succeed = false; } catch (Exception e) { Log.e("Haggle", "Unzip error: ", e); succeed = false; } return succeed; }
From source file:JarMaker.java
/** * @param f_name : source zip file path name * @param dir_name : target dir file path *//*from w w w .j a v a2 s . co m*/ public static void unpackJar(String f_name, String dir_name) throws IOException { BufferedInputStream bism = new BufferedInputStream(new FileInputStream(f_name)); ZipInputStream zism = new ZipInputStream(bism); for (ZipEntry z = zism.getNextEntry(); z != null; z = zism.getNextEntry()) { File f = new File(dir_name, z.getName()); if (z.isDirectory()) { f.mkdirs(); } else { f.getParentFile().mkdirs(); BufferedOutputStream bosm = new BufferedOutputStream(new FileOutputStream(f)); int i; byte[] buffer = new byte[1024 * 512]; try { while ((i = zism.read(buffer, 0, buffer.length)) != -1) bosm.write(buffer, 0, i); } catch (IOException ie) { throw ie; } bosm.close(); } } zism.close(); bism.close(); }
From source file:com.eviware.soapui.integration.exporter.ProjectExporter.java
public static void unpackageAll(String archive, String path) { try {//from www. j a v a 2s. c o m BufferedOutputStream dest = null; FileInputStream fis = new FileInputStream(archive); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { int count; byte data[] = new byte[BUFFER]; // write the files to the disk FileOutputStream fos = new FileOutputStream(path + File.separator + entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = zis.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); } zis.close(); } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.googlecode.osde.internal.profiling.Profile.java
/** * Unzips a zip content into a physical folder. * * @return The newly-created folder with the unzipped content. *//*www. j a v a2s . com*/ private static File unzip(InputStream resource, File output) throws IOException { // Allocate a 16K buffer to read the XPI file faster. ZipInputStream zipStream = new ZipInputStream(new BufferedInputStream(resource, 16 * 1024)); ZipEntry entry = zipStream.getNextEntry(); while (entry != null) { final File target = new File(output, entry.getName()); if (entry.isDirectory()) { forceMkdir(target); } else { unzipFile(target, zipStream); } entry = zipStream.getNextEntry(); } return output; }
From source file:de.pksoftware.springstrap.sapi.util.WebappZipper.java
/** * Unzip it/*from w ww . jav a2s .com*/ * @param zipFile input zip file * @param output zip file output folder */ public static void unzip(String zipFile, String outputFolder) { logger.info("Unzipping {} into {}.", zipFile, outputFolder); byte[] buffer = new byte[1024]; try { //get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { ze = zis.getNextEntry(); continue; } String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); logger.debug("Unzipping: {}", newFile.getAbsoluteFile()); //create all non exists folders //else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); logger.debug("Unzipping {} completed.", zipFile); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:net.sf.jasperreports.samples.wizards.SampleNewWizard.java
public static void unpackArchive(File theFile, File targetDir, IProgressMonitor monitor, Set<String> cpaths, Set<String> lpaths) { byte[] buffer = new byte[1024]; ZipInputStream zis = null; try {//from w w w. j a v a 2 s. c o m zis = new ZipInputStream(new FileInputStream(theFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { File file = new File(targetDir, File.separator + ze.getName()); new File(file.getParent()).mkdirs(); String fname = file.getName(); if (ze.isDirectory()) { if (fname.equals("src")) cpaths.add(ze.getName()); } else { FileOutputStream fos = new FileOutputStream(file); int len; while ((len = zis.read(buffer)) > 0) fos.write(buffer, 0, len); fos.close(); } if (file.getParentFile().getName().equals("lib") && (fname.endsWith(".jar") || fname.endsWith(".zip"))) lpaths.add(ze.getName()); if (monitor.isCanceled()) { zis.close(); return; } ze = zis.getNextEntry(); } } catch (IOException e) { e.printStackTrace(); } finally { try { zis.closeEntry(); zis.close(); } catch (IOException e) { e.printStackTrace(); } } }