use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat70 by apache.
the class TesterPerformance method testClassParserPerformance.
@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");
}
use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat70 by apache.
the class ContextConfig method processAnnotationsStream.
protected void processAnnotationsStream(InputStream is, WebXml fragment, boolean handlesTypesOnly) throws ClassFormatException, IOException {
ClassParser parser = new ClassParser(is);
JavaClass clazz = parser.parse();
checkHandlesTypes(clazz);
if (handlesTypesOnly) {
return;
}
String className = clazz.getClassName();
AnnotationEntry[] annotationsEntries = clazz.getAnnotationEntries();
if (annotationsEntries != null) {
for (AnnotationEntry ae : annotationsEntries) {
String type = ae.getAnnotationType();
if ("Ljavax/servlet/annotation/WebServlet;".equals(type)) {
processAnnotationWebServlet(className, ae, fragment);
} else if ("Ljavax/servlet/annotation/WebFilter;".equals(type)) {
processAnnotationWebFilter(className, ae, fragment);
} else if ("Ljavax/servlet/annotation/WebListener;".equals(type)) {
fragment.addListener(className);
} else {
// Unknown annotation - ignore
}
}
}
}
use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat70 by apache.
the class ContextConfig method populateJavaClassCache.
private void populateJavaClassCache(String className) {
if (!javaClassCache.containsKey(className)) {
String name = className.replace('.', '/') + ".class";
InputStream is = context.getLoader().getClassLoader().getResourceAsStream(name);
if (is == null) {
return;
}
ClassParser parser = new ClassParser(is);
try {
JavaClass clazz = parser.parse();
populateJavaClassCache(clazz.getClassName(), clazz);
} catch (ClassFormatException e) {
log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
} catch (IOException e) {
log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
} finally {
try {
is.close();
} catch (IOException e) {
// ignore
}
}
}
}
use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat by apache.
the class ContextConfig method processAnnotationsStream.
protected void processAnnotationsStream(InputStream is, WebXml fragment, boolean handlesTypesOnly, Map<String, JavaClassCacheEntry> javaClassCache) throws ClassFormatException, IOException {
ClassParser parser = new ClassParser(is);
JavaClass clazz = parser.parse();
checkHandlesTypes(clazz, javaClassCache);
if (handlesTypesOnly) {
return;
}
processClass(fragment, clazz);
}
use of org.apache.tomcat.util.bcel.classfile.ClassParser in project tomcat by apache.
the class ContextConfig method populateJavaClassCache.
private void populateJavaClassCache(String className, Map<String, JavaClassCacheEntry> javaClassCache) {
if (!javaClassCache.containsKey(className)) {
String name = className.replace('.', '/') + ".class";
try (InputStream is = context.getLoader().getClassLoader().getResourceAsStream(name)) {
if (is == null) {
return;
}
ClassParser parser = new ClassParser(is);
JavaClass clazz = parser.parse();
populateJavaClassCache(clazz.getClassName(), clazz, javaClassCache);
} catch (ClassFormatException | IOException e) {
log.debug(sm.getString("contextConfig.invalidSciHandlesTypes", className), e);
}
}
}
Aggregations