List of usage examples for java.util.zip ZipInputStream close
public void close() throws IOException
From source file:br.com.ingenieux.mojo.jbake.SeedMojo.java
private void unpackZip(File tmpZipFile) throws IOException { ZipInputStream zis = new ZipInputStream(new FileInputStream(tmpZipFile)); //get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { if (ze.isDirectory()) { ze = zis.getNextEntry();//from w w w . j a v a2 s. co m continue; } String fileName = stripLeadingPath(ze.getName()); File newFile = new File(outputDirectory + File.separator + fileName); new File(newFile.getParent()).mkdirs(); FileOutputStream fos = new FileOutputStream(newFile); IOUtils.copy(zis, fos); fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); }
From source file:de.micromata.genome.db.jpa.genomecore.chronos.JobStoreTest.java
License:asdf
public void findClassPathInJars() { try {/*from ww w . j ava 2 s .co m*/ Iterator it = FileUtils.iterateFiles(new File("."), new String[] { "jar" }, true); for (; it.hasNext();) { File f = (File) it.next(); ZipInputStream zf = new ZipInputStream(new FileInputStream(f)); ZipEntry ze; while ((ze = zf.getNextEntry()) != null) { String name = ze.getName(); if (name.startsWith("org/objectweb/asm") == true) { System.out.println("Found: " + f.getCanonicalPath()); zf.closeEntry(); break; } zf.closeEntry(); } zf.close(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.gradle.language.cpp.internal.NativeDependencyCache.java
private void unzipTo(File headersZip, File unzipDir) throws IOException { ZipInputStream inputStream = new ZipInputStream(new BufferedInputStream(new FileInputStream(headersZip))); try {//from ww w . j ava2 s. c o m ZipEntry entry = null; while ((entry = inputStream.getNextEntry()) != null) { if (entry.isDirectory()) { continue; } File outFile = new File(unzipDir, entry.getName()); Files.createParentDirs(outFile); FileOutputStream outputStream = new FileOutputStream(outFile); try { IOUtils.copyLarge(inputStream, outputStream); } finally { outputStream.close(); } } } finally { inputStream.close(); } }
From source file:edu.harvard.i2b2.eclipse.plugins.metadataLoader.util.FileUtil.java
public static void unzip(String zipname) throws IOException { FileInputStream fis = new FileInputStream(zipname); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); //?? GZIPInputStream gzis = new GZIPInputStream(new BufferedInputStream(fis)); // get directory of the zip file if (zipname.contains("\\")) zipname = zipname.replace("\\", "/"); // String zipDirectory = zipname.substring(0, zipname.lastIndexOf("/")+1) ; String zipDirectory = zipname.substring(0, zipname.lastIndexOf(".")); new File(zipDirectory).mkdir(); RunData.getInstance().setMetadataDirectory(zipDirectory); ZipEntry entry;//from ww w. j a v a 2 s . co m while ((entry = zis.getNextEntry()) != null) { System.out.println("Unzipping: " + entry.getName()); if (entry.getName().contains("metadata")) { RunData.getInstance().setMetadataFile(zipDirectory + "/" + entry.getName()); } else if (entry.getName().contains("schemes")) { RunData.getInstance().setSchemesFile(zipDirectory + "/" + entry.getName()); } else if (entry.getName().contains("access")) { RunData.getInstance().setTableAccessFile(zipDirectory + "/" + entry.getName()); } int size; byte[] buffer = new byte[2048]; FileOutputStream fos = new FileOutputStream(zipDirectory + "/" + entry.getName()); BufferedOutputStream bos = new BufferedOutputStream(fos, buffer.length); while ((size = zis.read(buffer, 0, buffer.length)) != -1) { bos.write(buffer, 0, size); } bos.flush(); bos.close(); } zis.close(); fis.close(); }
From source file:org.curriki.xwiki.plugin.asset.attachment.SankoreAssetManager.java
public void updateSubAssetClass(XWikiDocument assetDoc, String filetype, String category, XWikiAttachment attachment, XWikiContext context) { if (filetype.equals("ubz") || filetype.equals("ubw")) { String contents = new String(); ZipEntry ze = null;//from w w w . j a v a 2 s . c o m try { ZipInputStream zin = new ZipInputStream(attachment.getContentInputStream(context)); while ((ze = zin.getNextEntry()) != null) { if (ze.getName().equals("metadata.rdf")) { byte[] buffer = new byte[8192]; int len; while ((len = zin.read(buffer)) != -1) { String buffersz = new String(buffer, 0, len, "UTF-8"); contents += buffersz; } break; } } zin.close(); DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document dDoc = builder.parse(new ByteArrayInputStream(contents.getBytes("UTF8"))); XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new UniversalNamespaceResolver(dDoc)); assetDoc.setTitle(xPath.evaluate("RDF/Description/sessionTitle", dDoc)); assetDoc.setTags(xPath.evaluate("RDF/Description/sessionKeywords", dDoc), context); BaseObject assetObject = assetDoc.getObject(Constants.ASSET_CLASS); BaseObject licenceObject = assetDoc.getObject(Constants.ASSET_LICENCE_CLASS); assetObject.setLargeStringValue("description", xPath.evaluate("RDF/Description/sessionObjectives", dDoc)); assetObject.setStringValue("keywords", xPath.evaluate("RDF/Description/sessionKeywords", dDoc)); assetObject.setStringValue("language", "fr"); assetObject.setStringValue("education_system", "AssetMetadata.FranceEducation"); String xvalue = xPath.evaluate("RDF/Description/sessionGradeLevel", dDoc); if (!xvalue.isEmpty() && context.getWiki().exists("SankoreCode.GradeLevelMapping", context)) { String mappingString = context.getWiki().getDocument("SankoreCode.GradeLevelMapping", context) .getContent(); Scanner scanner = new Scanner(mappingString); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] pair = line.split("="); String key = pair[0]; if (key.equals(xvalue)) { xvalue = pair[1]; assetObject.setDBStringListValue("educational_level", Arrays.asList(xvalue.split(","))); break; } } } xvalue = xPath.evaluate("RDF/Description/sessionSubjects", dDoc); if (!xvalue.isEmpty() && context.getWiki().exists("SankoreCode.SubjectsMapping", context)) { String mappingString = context.getWiki().getDocument("SankoreCode.SubjectsMapping", context) .getContent(); Scanner scanner = new Scanner(mappingString); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] pair = line.split("="); String key = pair[0]; if (key.equals(xvalue)) { xvalue = pair[1]; assetObject.setDBStringListValue("fw_items", Arrays.asList(xvalue.split(","))); break; } } } xvalue = xPath.evaluate("RDF/Description/sessionType", dDoc); if (!xvalue.isEmpty() && context.getWiki().exists("SankoreCode.TypeMapping", context)) { String mappingString = context.getWiki().getDocument("SankoreCode.TypeMapping", context) .getContent(); Scanner scanner = new Scanner(mappingString); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] pair = line.split("="); String key = pair[0]; if (key.equals(xvalue)) { xvalue = pair[1]; assetObject.setDBStringListValue("instructional_component", Arrays.asList(xvalue.split(","))); break; } } } xvalue = xPath.evaluate("RDF/Description/sessionLicence", dDoc); if (!xvalue.isEmpty() && context.getWiki().exists("SankoreCode.LicenseMapping", context)) { String mappingString = context.getWiki().getDocument("SankoreCode.LicenseMapping", context) .getContent(); Scanner scanner = new Scanner(mappingString); while (scanner.hasNextLine()) { String line = scanner.nextLine(); String[] pair = line.split("="); String key = pair[0]; if (key.equals(xvalue)) { xvalue = pair[1]; licenceObject.setStringValue("licenseType", xvalue); break; } } } licenceObject.setStringValue("rightsHolder", xPath.evaluate("RDF/Description/sessionAuthors", dDoc)); } catch (IOException ioe) { LOG.error("Unexpected exception ", ioe); } catch (ParserConfigurationException pce) { LOG.error("Unexpected exception ", pce); } catch (SAXException saxe) { LOG.error("Unexpected exception ", saxe); } catch (XPathException xpe) { LOG.error("Unexpected exception ", xpe); } catch (XWikiException xe) { LOG.error("Unexpected exception ", xe); } } }
From source file:com.nextep.designer.repository.services.impl.RepositoryUpdaterService.java
/** * Creates the specified delivery (ZIP resource file) on the temporary directory of the local * file system.//from ww w. j a v a2s .c o m * * @param deliveryResource java resource zip file * @return a <code>String</code> representing the absolute path to the delivery root directory. */ private static String createTempDelivery(String deliveryResource) { InputStream is = RepositoryUpdaterService.class.getResourceAsStream(deliveryResource); if (is == null) { throw new ErrorException("Unable to load delivery file: " + deliveryResource); //$NON-NLS-1$ } final String exportLoc = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$ ZipInputStream zipInput = new ZipInputStream(is); ZipEntry entry = null; String rootDeliveryDir = null; try { while ((entry = zipInput.getNextEntry()) != null) { File targetFile = new File(exportLoc, entry.getName()); if (rootDeliveryDir == null) { /* * Initialize the delivery root directory value by searching recursively for the * shallowest directory in the path. */ rootDeliveryDir = getDeliveryRootPath(targetFile, new File(exportLoc)); } if (entry.isDirectory()) { targetFile.mkdirs(); } else { File targetDir = targetFile.getParentFile(); if (!targetDir.exists()) { /* * Creates the directory including any necessary but nonexistent parent * directories. */ targetDir.mkdirs(); } FileOutputStream outFile = new FileOutputStream(targetFile); copyStreams(zipInput, outFile); outFile.close(); } zipInput.closeEntry(); } } catch (IOException e) { throw new ErrorException(e); } finally { try { zipInput.close(); } catch (IOException e) { throw new ErrorException(e); } } return rootDeliveryDir; }
From source file:aurelienribon.gdxsetupui.ProjectSetup.java
/** * The raw structure of all projects is contained in a zip file. This * method inflates this file in a temporary folder. * @throws IOException/*w ww . j av a 2s . c o m*/ */ public void inflateProjects() throws IOException { FileUtils.forceMkdir(tmpDst); FileUtils.cleanDirectory(tmpDst); InputStream is = Res.getStream("projects.zip"); ZipInputStream zis = new ZipInputStream(is); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { File file = new File(tmpDst, entry.getName()); if (entry.isDirectory()) { FileUtils.forceMkdir(file); } else { OutputStream os = new FileOutputStream(file); IOUtils.copy(zis, os); os.close(); } } zis.close(); }
From source file:com.squareup.wire.schema.internal.parser.RpcMethodScanner.java
private List<RpcMethodDefinition> searchJar(String jarpath, String serviceName) throws IOException { List<RpcMethodDefinition> defs = new ArrayList<>(); File jarFile = new File(jarpath); if (!jarFile.exists() || jarFile.isDirectory()) { return defs; }// ww w . ja v a 2 s . co m ZipInputStream zip = new ZipInputStream(new FileInputStream(jarFile)); ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { String entryName = ze.getName(); if (entryName.endsWith(".proto")) { ZipFile zipFile = new ZipFile(jarFile); try (InputStream in = zipFile.getInputStream(ze)) { defs.addAll(inspectProtoFile(in, serviceName)); if (!defs.isEmpty()) { zipFile.close(); break; } } zipFile.close(); } } zip.close(); return defs; }
From source file:br.eti.ranieri.opcoesweb.importacao.offline.ImportadorOffline.java
public void importar(URL url, ConfiguracaoImportacao configuracaoImportacao) throws Exception { HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new Exception("Requisio HTTP retornou cdigo de erro: " + connection.getResponseCode()); }//w w w.j a v a2 s . c om List<CotacaoBDI> cotacoes = null; ZipInputStream zip = null; try { zip = new ZipInputStream(connection.getInputStream()); ZipEntry entry; while ((entry = zip.getNextEntry()) != null) { if ("BDIN".equals(entry.getName())) { cotacoes = parser.parseBDI(zip); zip.closeEntry(); break; } else if (entry.getName().startsWith("COTAHIST_") && entry.getName().endsWith(".TXT")) { cotacoes = parser.parseHistorico(zip); zip.closeEntry(); break; } } zip.close(); } catch (ZipException e) { log.error("Formato invalido de arquivo zip", e); } catch (IOException e) { log.error("Erro de leitura do arquivo zip", e); } finally { if (zip != null) IOUtils.closeQuietly(zip); } calcularBlackScholes(cotacoes, configuracaoImportacao); }
From source file:ZipTest.java
/** * Loads a file from the ZIP archive into the text area * @param name the name of the file in the archive *//*from w w w. j ava 2s .c om*/ public void loadZipFile(final String name) { fileCombo.setEnabled(false); fileText.setText(""); new SwingWorker<Void, Void>() { protected Void doInBackground() throws Exception { try { ZipInputStream zin = new ZipInputStream(new FileInputStream(zipname)); ZipEntry entry; // find entry with matching name in archive while ((entry = zin.getNextEntry()) != null) { if (entry.getName().equals(name)) { // read entry into text area Scanner in = new Scanner(zin); while (in.hasNextLine()) { fileText.append(in.nextLine()); fileText.append("\n"); } } zin.closeEntry(); } zin.close(); } catch (IOException e) { e.printStackTrace(); } return null; } protected void done() { fileCombo.setEnabled(true); } }.execute(); }