List of usage examples for java.util.jar JarInputStream getNextJarEntry
public JarEntry getNextJarEntry() throws IOException
From source file:org.bimserver.plugins.JarClassLoader.java
private void loadSubJars(byte[] byteArray) { try {/*from w w w.jav a2 s .com*/ JarInputStream jarInputStream = new JarInputStream(new ByteArrayInputStream(byteArray)); JarEntry entry = jarInputStream.getNextJarEntry(); while (entry != null) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(jarInputStream, byteArrayOutputStream); map.put(entry.getName(), byteArrayOutputStream.toByteArray()); entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); } catch (IOException e) { LOGGER.error("", e); } }
From source file:se.crisp.codekvast.support.web.config.WebjarVersionFilter.java
private void analyzeJar(URL jarUrl, Pattern pattern) throws IOException { // Look for entries that match the pattern... JarInputStream inputStream = new JarInputStream(jarUrl.openStream()); JarEntry jarEntry = inputStream.getNextJarEntry(); while (jarEntry != null) { log.trace("Considering {}", jarEntry); Matcher matcher = pattern.matcher(jarEntry.getName()); if (matcher.matches()) { String key = matcher.group(1); String value = matcher.group(2); versions.put(key, value);//from ww w.ja va 2s. c o m log.debug("{} is a webjar, adding {}={} to map", basename(jarUrl.getPath()), key, value); return; } jarEntry = inputStream.getNextJarEntry(); } }
From source file:org.bimserver.plugins.classloaders.JarClassLoader.java
public JarClassLoader(ClassLoader parentClassLoader, File jarFile) throws FileNotFoundException, IOException { super(parentClassLoader); this.jarFile = jarFile; JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry entry = jarInputStream.getNextJarEntry(); while (entry != null) { if (entry.getName().endsWith(".jar")) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(jarInputStream, byteArrayOutputStream); // Not storing the original JAR, so future code will be unable to read the original loadSubJars(byteArrayOutputStream.toByteArray()); } else {// ww w .ja v a 2s.c om // Files are being stored deflated in memory because most of the time a lot of files are not being used (or the complete plugin is not being used) addDataToMap(jarInputStream, entry); } entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); }
From source file:org.bimserver.plugins.classloaders.JarClassLoader.java
private void loadSubJars(byte[] byteArray) { try {//from w w w . j a v a 2 s.co m JarInputStream jarInputStream = new JarInputStream(new ByteArrayInputStream(byteArray)); JarEntry entry = jarInputStream.getNextJarEntry(); while (entry != null) { addDataToMap(jarInputStream, entry); entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); } catch (IOException e) { LOGGER.error("", e); } }
From source file:org.jahia.modules.serversettings.portlets.BasePortletHelper.java
void copyEntries(JarInputStream source, JarOutputStream dest) throws IOException { JarEntry originalJarEntry = source.getNextJarEntry(); while (originalJarEntry != null) { final JarEntry newJarEntry = cloneEntry(originalJarEntry); dest.putNextEntry(newJarEntry);//from w ww. j a va2 s .com if (!handled(originalJarEntry, source, dest)) { IOUtils.copy(source, dest); } dest.closeEntry(); dest.flush(); originalJarEntry = source.getNextJarEntry(); } }
From source file:org.bimserver.plugins.classloaders.MemoryJarClassLoader.java
public MemoryJarClassLoader(ClassLoader parentClassLoader, File jarFile) throws FileNotFoundException, IOException { super(parentClassLoader); this.jarFile = jarFile; JarInputStream jarInputStream = new JarInputStream(new FileInputStream(jarFile)); JarEntry entry = jarInputStream.getNextJarEntry(); while (entry != null) { if (entry.getName().endsWith(".jar")) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(jarInputStream, byteArrayOutputStream); // Not storing the original JAR, so future code will be unable to read the original loadSubJars(byteArrayOutputStream.toByteArray()); } else {//from w w w .ja va2s . c om // Files are being stored deflated in memory because most of the time a lot of files are not being used (or the complete plugin is not being used) addDataToMap(jarInputStream, entry); } entry = jarInputStream.getNextJarEntry(); } jarInputStream.close(); }
From source file:gov.nih.nci.restgen.util.JarHelper.java
/** * Given an InputStream on a jar file, unjars the contents into the given * directory.// www. j a va 2 s .c om */ public void unjar(InputStream in, File destDir) throws IOException { BufferedOutputStream dest = null; JarInputStream jis = new JarInputStream(in); JarEntry entry; while ((entry = jis.getNextJarEntry()) != null) { if (entry.isDirectory()) { File dir = new File(destDir, entry.getName()); dir.mkdir(); if (entry.getTime() != -1) dir.setLastModified(entry.getTime()); continue; } int count; byte data[] = new byte[BUFFER_SIZE]; File destFile = new File(destDir, entry.getName()); if (mVerbose) { //System.out.println("unjarring " + destFile + " from " + entry.getName()); } FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, BUFFER_SIZE); while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); if (entry.getTime() != -1) destFile.setLastModified(entry.getTime()); } jis.close(); }
From source file:org.n52.ifgicopter.spf.common.PluginRegistry.java
/** * @param jar//from w w w . j av a2 s. com * the jar * @return list of fqcn */ private List<String> listClasses(File jar) throws IOException { ArrayList<String> result = new ArrayList<String>(); JarInputStream jis = new JarInputStream(new FileInputStream(jar)); JarEntry je; while (jis.available() > 0) { je = jis.getNextJarEntry(); if (je != null) { if (je.getName().endsWith(".class")) { result.add(je.getName().replaceAll("/", "\\.").substring(0, je.getName().indexOf(".class"))); } } } return result; }
From source file:com.thoughtworks.go.util.NestedJarClassLoader.java
private URL[] enumerateJar(URL urlOfJar) { LOGGER.debug("Enumerating jar: {}", urlOfJar); List<URL> urls = new ArrayList<>(); urls.add(urlOfJar);/*from w w w . j a va2 s.c om*/ try { JarInputStream jarStream = new JarInputStream(urlOfJar.openStream()); JarEntry entry; while ((entry = jarStream.getNextJarEntry()) != null) { if (!entry.isDirectory() && entry.getName().endsWith(".jar")) { urls.add(expandJarAndReturnURL(jarStream, entry)); } } } catch (IOException e) { LOGGER.error("Failed to enumerate jar {}", urlOfJar, e); } return urls.toArray(new URL[0]); }
From source file:org.apache.pluto.util.assemble.io.AssemblyStreamTest.java
protected void verifyAssembly(File warFile) throws Exception { PlutoWebXmlRewriter webXmlRewriter = null; PortletAppDescriptorService portletSvc = new PortletAppDescriptorServiceImpl(); int entryCount = 0; ByteArrayOutputStream portletXmlBytes = new ByteArrayOutputStream(); ByteArrayOutputStream webXmlBytes = new ByteArrayOutputStream(); PortletApplicationDefinition portletApp = null; JarInputStream assembledWarIn = new JarInputStream(new FileInputStream(warFile)); JarEntry tempEntry;// w w w .j av a 2 s . co m while ((tempEntry = assembledWarIn.getNextJarEntry()) != null) { entryCount++; if (Assembler.PORTLET_XML.equals(tempEntry.getName())) { IOUtils.copy(assembledWarIn, portletXmlBytes); portletApp = portletSvc.read("test", "/test", new ByteArrayInputStream(portletXmlBytes.toByteArray())); } if (Assembler.SERVLET_XML.equals(tempEntry.getName())) { IOUtils.copy(assembledWarIn, webXmlBytes); webXmlRewriter = new PlutoWebXmlRewriter(new ByteArrayInputStream(webXmlBytes.toByteArray())); } } assertTrue("Assembled WAR file was empty.", entryCount > 0); assertNotNull("Web Application Descripter was null.", webXmlRewriter); assertNotNull("Portlet Application Descriptor was null.", portletApp); assertTrue("Portlet Application Descriptor doesn't define any portlets.", portletApp.getPortlets().size() > 0); assertTrue("Web Application Descriptor doesn't define any servlets.", webXmlRewriter.hasServlets()); assertTrue("Web Application Descriptor doesn't define any servlet mappings.", webXmlRewriter.hasServletMappings()); PortletDefinition portlet = (PortletDefinition) portletApp.getPortlets().iterator().next(); assertTrue("Unable to retrieve test portlet named [" + testPortletName + "]", portlet.getPortletName().equals(testPortletName)); String servletClassName = webXmlRewriter.getServletClass(testPortletName); assertNotNull("Unable to retrieve portlet dispatch for portlet named [" + testPortletName + "]", servletClassName); assertEquals("Dispatcher servlet incorrect for test portlet [" + testPortletName + "]", Assembler.DISPATCH_SERVLET_CLASS, servletClassName); }