Lines 17-22
Link Here
|
17 |
package org.apache.tomcat.util.bcel; |
17 |
package org.apache.tomcat.util.bcel; |
18 |
|
18 |
|
19 |
import java.io.File; |
19 |
import java.io.File; |
|
|
20 |
import java.io.FilterInputStream; |
20 |
import java.io.IOException; |
21 |
import java.io.IOException; |
21 |
import java.io.InputStream; |
22 |
import java.io.InputStream; |
22 |
import java.net.URL; |
23 |
import java.net.URL; |
Lines 34-39
Link Here
|
34 |
|
35 |
|
35 |
private static final String JAR_LOCATION = "/tmp/jira-libs"; |
36 |
private static final String JAR_LOCATION = "/tmp/jira-libs"; |
36 |
|
37 |
|
|
|
38 |
/** |
39 |
* An InputStream that returns no more than one byte on each call. |
40 |
*/ |
41 |
private static class SlowInputStream extends FilterInputStream { |
42 |
|
43 |
public SlowInputStream(InputStream in) { |
44 |
super(in); |
45 |
} |
46 |
|
47 |
@Override |
48 |
public int read(byte[] b, int off, int len) throws IOException { |
49 |
if (len <= 0) { |
50 |
if (len == 0) { |
51 |
return 0; |
52 |
} |
53 |
throw new IndexOutOfBoundsException(); |
54 |
} |
55 |
return super.read(b, off, 1); |
56 |
} |
57 |
|
58 |
@Override |
59 |
public int available() throws IOException { |
60 |
int result = super.available(); |
61 |
return result > 0 ? 1 : result; |
62 |
} |
63 |
} |
64 |
|
37 |
@Test |
65 |
@Test |
38 |
public void testClassParserPerformance() throws IOException { |
66 |
public void testClassParserPerformance() throws IOException { |
39 |
File libDir = new File(JAR_LOCATION); |
67 |
File libDir = new File(JAR_LOCATION); |
Lines 57-62
Link Here
|
57 |
while (jarEntryName != null) { |
85 |
while (jarEntryName != null) { |
58 |
if (jarEntryName.endsWith(".class")) { |
86 |
if (jarEntryName.endsWith(".class")) { |
59 |
InputStream is = jar.getEntryInputStream(); |
87 |
InputStream is = jar.getEntryInputStream(); |
|
|
88 |
is = new SlowInputStream(is); |
60 |
long start = System.nanoTime(); |
89 |
long start = System.nanoTime(); |
61 |
ClassParser cp = new ClassParser(is); |
90 |
ClassParser cp = new ClassParser(is); |
62 |
cp.parse(); |
91 |
cp.parse(); |