Lines 17-27
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; |
23 |
import java.util.HashSet; |
24 |
import java.util.HashSet; |
24 |
import java.util.Locale; |
25 |
import java.util.Locale; |
|
|
26 |
import java.util.Random; |
25 |
import java.util.Set; |
27 |
import java.util.Set; |
26 |
|
28 |
|
27 |
import org.junit.Test; |
29 |
import org.junit.Test; |
Lines 34-39
Link Here
|
34 |
|
36 |
|
35 |
private static final String JAR_LOCATION = "/tmp/jira-libs"; |
37 |
private static final String JAR_LOCATION = "/tmp/jira-libs"; |
36 |
|
38 |
|
|
|
39 |
/** |
40 |
* An InputStream that returns less bytes than a read(byte[]) call asks for. |
41 |
*/ |
42 |
private static class SlowInputStream extends FilterInputStream { |
43 |
|
44 |
private final Random r = new Random(); |
45 |
|
46 |
public SlowInputStream(InputStream in) { |
47 |
super(in); |
48 |
} |
49 |
|
50 |
@Override |
51 |
public int read(byte[] b, int off, int len) throws IOException { |
52 |
if (len <= 0) { |
53 |
if (len == 0) { |
54 |
return 0; |
55 |
} |
56 |
throw new IndexOutOfBoundsException(); |
57 |
} |
58 |
int randomLength = 1 + r.nextInt(len); |
59 |
return super.read(b, off, randomLength); |
60 |
} |
61 |
|
62 |
@Override |
63 |
public int available() throws IOException { |
64 |
int result = super.available(); |
65 |
return result > 0 ? 1 : result; |
66 |
} |
67 |
} |
68 |
|
37 |
@Test |
69 |
@Test |
38 |
public void testClassParserPerformance() throws IOException { |
70 |
public void testClassParserPerformance() throws IOException { |
39 |
File libDir = new File(JAR_LOCATION); |
71 |
File libDir = new File(JAR_LOCATION); |
Lines 57-62
Link Here
|
57 |
while (jarEntryName != null) { |
89 |
while (jarEntryName != null) { |
58 |
if (jarEntryName.endsWith(".class")) { |
90 |
if (jarEntryName.endsWith(".class")) { |
59 |
InputStream is = jar.getEntryInputStream(); |
91 |
InputStream is = jar.getEntryInputStream(); |
|
|
92 |
is = new SlowInputStream(is); |
60 |
long start = System.nanoTime(); |
93 |
long start = System.nanoTime(); |
61 |
ClassParser cp = new ClassParser(is); |
94 |
ClassParser cp = new ClassParser(is); |
62 |
cp.parse(); |
95 |
cp.parse(); |