List of usage examples for java.util.zip ZipInputStream close
public void close() throws IOException
From source file:com.microsoft.azure.hdinsight.util.HDInsightJobViewUtils.java
public static void unzip(String zipFilePath, String destDirectory) throws IOException { File destDir = new File(destDirectory); if (!destDir.exists()) { destDir.mkdir();/*from ww w . j a v a 2s. c o m*/ } ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath)); ZipEntry entry = zipIn.getNextEntry(); while (entry != null) { String filePath = destDirectory + File.separator + entry.getName(); if (!entry.isDirectory()) { extractFile(zipIn, filePath); } else { File dir = new File(filePath); dir.mkdir(); } zipIn.closeEntry(); entry = zipIn.getNextEntry(); } zipIn.close(); }
From source file:com.twinsoft.convertigo.engine.util.ZipUtils.java
/*** Added by julienda - 08/09/2012 * Return the project name by reading the first directory into the archive (.car) * @param path: the archive path//from w w w . j ava2s .c o m * @return filename: the project name * @throws IOException */ public static String getProjectName(String path) throws IOException { Engine.logEngine.trace("PATH: " + path); ZipInputStream zis = new ZipInputStream(new FileInputStream(path)); ZipEntry ze = null; String fileName = null; try { if ((ze = zis.getNextEntry()) != null) { fileName = ze.getName().replaceAll("/.*", ""); Engine.logEngine.trace("ZipUtils.getProjectName() - fileName: " + fileName); } } finally { zis.close(); } return fileName; }
From source file:Main.java
/*** * Extract zipfile to outdir with complete directory structure * disclaimer, I didn't wrote that .../*from w ww .j ava2 s. c o m*/ * @param zipfile Input .zip file * @param outdir Output directory */ public static void extract(File zipfile, File outdir) { // todo: replace with more trustful method try { ZipInputStream zin = new ZipInputStream(new FileInputStream(zipfile)); ZipEntry entry; String name, dir; while ((entry = zin.getNextEntry()) != null) { name = entry.getName(); if (entry.isDirectory()) { mkdirs(outdir, name); continue; } dir = dirpart(name); if (dir != null) { mkdirs(outdir, dir); } extractFile(zin, outdir, name); } zin.close(); } catch (IOException err) { throw new RuntimeException("Unable to extract quiz", err); } }
From source file:Main.java
/*** * Extract zipfile to outdir with complete directory structure * @param zipfile Input .zip file// www. j av a 2 s. c om * @param outdir Output directory */ public static void extract(InputStream zipfile, File outdir) { try { ZipInputStream zin = new ZipInputStream(zipfile); ZipEntry entry; String name, dir; Log.i("OF", "uncompressinggggg "); while ((entry = zin.getNextEntry()) != null) { name = entry.getName(); if (entry.isDirectory()) { mkdirs(outdir, name); continue; } dir = dirpart(name); if (dir != null) mkdirs(outdir, dir); extractFile(zin, outdir, name); } zin.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ZipHandler.java
/** * unzipps a zip file placed at <zipURL> to path <xmlURL> * @param zipURL//from w ww . j a v a 2s . c om * @param xmlURL */ public static void unZip(String zipURL, String xmlURL) throws IOException { FileOutputStream fosBLOB = new FileOutputStream(new File("c:\\")); FileOutputStream fosCLOB = new FileOutputStream(new File("c:\\")); FileInputStream fis = new FileInputStream(new File(zipURL)); ZipInputStream zis = new ZipInputStream(fis); FileOutputStream fos = new FileOutputStream(xmlURL); ZipEntry ze = zis.getNextEntry(); ExtractZip(zis, fos, fosBLOB, fosCLOB, ze); ze = zis.getNextEntry(); ExtractZip(zis, fos, fosBLOB, fosCLOB, ze); ze = zis.getNextEntry(); ExtractZip(zis, fos, fosBLOB, fosCLOB, ze); fos.flush(); fis.close(); fos.close(); fosCLOB.close(); fosBLOB.close(); zis.close(); }
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 av a2s .co m * * @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:org.asciidoctor.gradle.ZipUtils.java
/** * Unzips a file from an input stream to a location specified by the ZipFileFactory interface. * @param zip//from w ww. j a v a2 s . c om * @param zipFileFactory * @throws IOException */ static void unzip(InputStream zip, ZipFileFactory zipFileFactory) throws IOException { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(zip)); ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { File unzippedFile = zipFileFactory.createUnzippedFile(zipEntry); if (zipEntry.isDirectory()) { unzippedFile.mkdirs(); } else { unzippedFile.getParentFile().mkdirs(); FileOutputStream fos = new FileOutputStream(unzippedFile); IOUtils.copy(zis, fos); } zipEntry = zis.getNextEntry(); } zis.closeEntry(); zis.close(); }
From source file:com.google.gdt.eclipse.designer.gwtext.actions.ConfigureGwtExtOperation.java
private static void extractZip(InputStream zipFile, IFolder targetFolder) throws Exception { ZipInputStream zipInputStream = new ZipInputStream(zipFile); while (true) { ZipEntry zipEntry = zipInputStream.getNextEntry(); if (zipEntry == null) { break; }//from www .j av a 2s . com if (!zipEntry.isDirectory()) { String entryName = zipEntry.getName(); byte[] byteArray = IOUtils.toByteArray(zipInputStream); IOUtils2.setFileContents(targetFolder.getFile(new Path(entryName)), new ByteArrayInputStream(byteArray)); } zipInputStream.closeEntry(); } zipInputStream.close(); }
From source file:Main.java
/** * Reads the in_stream and extracts them to out_dir. * @param in_stream Input stream corresponding to the zip file. * @param out_dir Output directory for the zip file contents. * @throws IOException/*w w w. j a v a 2 s . c o m*/ */ public static void zipExtract(InputStream in_stream, File out_dir) throws IOException { if (!out_dir.exists()) { if (!out_dir.mkdirs()) { throw new IOException("Could not create output directory: " + out_dir.getAbsolutePath()); } } ZipInputStream zis = new ZipInputStream(in_stream); ZipEntry ze; byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((ze = zis.getNextEntry()) != null) { if (ze.isDirectory()) { File fmd = new File(out_dir.getAbsolutePath() + "/" + ze.getName()); fmd.mkdirs(); continue; } FileOutputStream fout = new FileOutputStream(out_dir.getAbsolutePath() + "/" + ze.getName()); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } zis.close(); }
From source file:io.druid.java.util.common.CompressionUtils.java
/** * Decompress an input stream from a file, based on the filename. *//*from w ww.j av a 2 s .c o m*/ public static InputStream decompress(final InputStream in, final String fileName) throws IOException { if (fileName.endsWith(GZ_SUFFIX)) { return gzipInputStream(in); } else if (fileName.endsWith(BZ2_SUFFIX)) { return new BZip2CompressorInputStream(in, true); } else if (fileName.endsWith(XZ_SUFFIX)) { return new XZCompressorInputStream(in, true); } else if (fileName.endsWith(ZIP_SUFFIX)) { // This reads the first file in the archive. final ZipInputStream zipIn = new ZipInputStream(in, StandardCharsets.UTF_8); try { final ZipEntry nextEntry = zipIn.getNextEntry(); if (nextEntry == null) { zipIn.close(); // No files in the archive - return an empty stream. return new ByteArrayInputStream(new byte[0]); } return zipIn; } catch (IOException e) { try { zipIn.close(); } catch (IOException e2) { e.addSuppressed(e2); } throw e; } } else { return in; } }