Java Code Examples for org.apache.tomcat.util.scan.Jar#getEntryInputStream()
The following examples show how to use
org.apache.tomcat.util.scan.Jar#getEntryInputStream() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TldLocationsCache.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
private void tldScanJar(JarURLConnection jarConn) throws IOException { Jar jar = null; InputStream is; boolean foundTld = false; URL resourceURL = jarConn.getJarFileURL(); String resourcePath = resourceURL.toString(); try { jar = JarFactory.newInstance(jarConn.getURL()); jar.nextEntry(); String entryName = jar.getEntryName(); while (entryName != null) { if (entryName.startsWith("META-INF/") && entryName.endsWith(".tld")) { is = null; try { is = jar.getEntryInputStream(); foundTld = true; tldScanStream(resourcePath, entryName, is); } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { // Ignore } } } } jar.nextEntry(); entryName = jar.getEntryName(); } } finally { if (jar != null) { jar.close(); } } if (!foundTld) { if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jsp.tldCache.noTldInJar", resourcePath)); } else if (showTldScanWarning) { // Not entirely thread-safe but a few duplicate log messages are // not a huge issue showTldScanWarning = false; log.info(Localizer.getMessage("jsp.tldCache.noTldSummary")); } } }
Example 2
Source File: TesterPerformance.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
@Test public void testClassParserPerformance() throws IOException { File libDir = new File(JAR_LOCATION); String[] libs = libDir.list(); Assert.assertNotNull(libs); Set<URL> jarURLs = new HashSet<URL>(); for (String lib : libs) { if (!lib.toLowerCase(Locale.ENGLISH).endsWith(".jar")) { continue; } jarURLs.add(new URL("jar:" + new File (libDir, lib).toURI().toURL().toExternalForm() + "!/")); } long duration = 0; for (URL jarURL : jarURLs) { Jar jar = JarFactory.newInstance(jarURL); try { jar.nextEntry(); String jarEntryName = jar.getEntryName(); while (jarEntryName != null) { if (jarEntryName.endsWith(".class")) { InputStream is = jar.getEntryInputStream(); long start = System.nanoTime(); ClassParser cp = new ClassParser(is); cp.parse(); duration += System.nanoTime() - start; } jar.nextEntry(); jarEntryName = jar.getEntryName(); } } finally { jar.close(); } } System.out.println("ClassParser performance test took: " + duration + " ns"); }
Example 3
Source File: TldLocationsCache.java From tomcatsrc with Apache License 2.0 | 4 votes |
private void tldScanJar(JarURLConnection jarConn) throws IOException { Jar jar = null; InputStream is; boolean foundTld = false; URL resourceURL = jarConn.getJarFileURL(); String resourcePath = resourceURL.toString(); try { jar = JarFactory.newInstance(jarConn.getURL()); jar.nextEntry(); String entryName = jar.getEntryName(); while (entryName != null) { if (entryName.startsWith("META-INF/") && entryName.endsWith(".tld")) { is = null; try { is = jar.getEntryInputStream(); foundTld = true; tldScanStream(resourcePath, entryName, is); } finally { if (is != null) { try { is.close(); } catch (IOException ioe) { // Ignore } } } } jar.nextEntry(); entryName = jar.getEntryName(); } } finally { if (jar != null) { jar.close(); } } if (!foundTld) { if (log.isDebugEnabled()) { log.debug(Localizer.getMessage("jsp.tldCache.noTldInJar", resourcePath)); } else if (showTldScanWarning) { // Not entirely thread-safe but a few duplicate log messages are // not a huge issue showTldScanWarning = false; log.info(Localizer.getMessage("jsp.tldCache.noTldSummary")); } } }
Example 4
Source File: TesterPerformance.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Test public void testClassParserPerformance() throws IOException { File libDir = new File(JAR_LOCATION); String[] libs = libDir.list(); Assert.assertNotNull(libs); Set<URL> jarURLs = new HashSet<URL>(); for (String lib : libs) { if (!lib.toLowerCase(Locale.ENGLISH).endsWith(".jar")) { continue; } jarURLs.add(new URL("jar:" + new File (libDir, lib).toURI().toURL().toExternalForm() + "!/")); } long duration = 0; for (URL jarURL : jarURLs) { Jar jar = JarFactory.newInstance(jarURL); try { jar.nextEntry(); String jarEntryName = jar.getEntryName(); while (jarEntryName != null) { if (jarEntryName.endsWith(".class")) { InputStream is = jar.getEntryInputStream(); long start = System.nanoTime(); ClassParser cp = new ClassParser(is); cp.parse(); duration += System.nanoTime() - start; } jar.nextEntry(); jarEntryName = jar.getEntryName(); } } finally { jar.close(); } } System.out.println("ClassParser performance test took: " + duration + " ns"); }