--- test/org/apache/tomcat/util/bcel/TesterPerformance.java (revision 1637495) +++ test/org/apache/tomcat/util/bcel/TesterPerformance.java (working copy) @@ -17,6 +17,7 @@ package org.apache.tomcat.util.bcel; import java.io.File; +import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -34,6 +35,33 @@ private static final String JAR_LOCATION = "/tmp/jira-libs"; + /** + * An InputStream that returns no more than one byte on each call. + */ + private static class SlowInputStream extends FilterInputStream { + + public SlowInputStream(InputStream in) { + super(in); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (len <= 0) { + if (len == 0) { + return 0; + } + throw new IndexOutOfBoundsException(); + } + return super.read(b, off, 1); + } + + @Override + public int available() throws IOException { + int result = super.available(); + return result > 0 ? 1 : result; + } + } + @Test public void testClassParserPerformance() throws IOException { File libDir = new File(JAR_LOCATION); @@ -57,6 +85,7 @@ while (jarEntryName != null) { if (jarEntryName.endsWith(".class")) { InputStream is = jar.getEntryInputStream(); + is = new SlowInputStream(is); long start = System.nanoTime(); ClassParser cp = new ClassParser(is); cp.parse();