();
- for (Attribute attribute : attrs) {
+ for (int i = 0; i < attrs.length; i++) {
+ Attribute attribute = attrs[i];
if (attribute instanceof Annotations) {
Annotations runtimeAnnotations = (Annotations)attribute;
for(int j = 0; j < runtimeAnnotations.getAnnotationEntries().length; j++)
diff --git a/java/org/apache/tomcat/util/bcel/classfile/LineNumber.java b/java/org/apache/tomcat/util/bcel/classfile/LineNumber.java
index dbe1ef8..be24182 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/LineNumber.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/LineNumber.java
@@ -27,6 +27,7 @@ import java.io.Serializable;
* the source that corresponds to a relative address in the byte code. This
* is used for debugging purposes.
*
+ * @version $Id$
* @author M. Dahm
* @see LineNumberTable
*/
diff --git a/java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java b/java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java
index a4079fa..0443046 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/LineNumberTable.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -27,6 +27,7 @@ import org.apache.tomcat.util.bcel.Constants;
* purposes. This attribute is used by the Code attribute. It
* contains pairs of PCs and line numbers.
*
+ * @version $Id$
* @author M. Dahm
* @see Code
* @see LineNumber
@@ -59,7 +60,7 @@ public final class LineNumberTable extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- LineNumberTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ LineNumberTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (LineNumber[]) null, constant_pool);
line_number_table_length = (file.readUnsignedShort());
diff --git a/java/org/apache/tomcat/util/bcel/classfile/LocalVariable.java b/java/org/apache/tomcat/util/bcel/classfile/LocalVariable.java
index 6da8f2c..6f47280 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/LocalVariable.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/LocalVariable.java
@@ -28,6 +28,7 @@ import org.apache.tomcat.util.bcel.Constants;
* This class represents a local variable within a method. It contains its
* scope, name, signature and index on the method's frame.
*
+ * @version $Id$
* @author M. Dahm
* @see LocalVariableTable
*/
diff --git a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java b/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java
index 91dd126..e13623c 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTable.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,6 +26,7 @@ import org.apache.tomcat.util.bcel.Constants;
* This class represents colection of local variables in a
* method. This attribute is contained in the Code attribute.
*
+ * @version $Id$
* @author M. Dahm
* @see Code
* @see LocalVariable
@@ -58,7 +59,7 @@ public class LocalVariableTable extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- LocalVariableTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ LocalVariableTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (LocalVariable[]) null, constant_pool);
local_variable_table_length = (file.readUnsignedShort());
diff --git a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java b/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java
index 2581b2f..7e2b38e 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/LocalVariableTypeTable.java
@@ -16,7 +16,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -61,7 +61,7 @@ private int local_variable_type_table_length; // Table of local
setLocalVariableTable(local_variable_table);
}
- LocalVariableTypeTable(int nameIdx, int len, DataInputStream dis,ConstantPool cpool) throws IOException {
+ LocalVariableTypeTable(int nameIdx, int len, DataInput dis,ConstantPool cpool) throws IOException {
this(nameIdx, len, (LocalVariable[])null, cpool);
local_variable_type_table_length = (dis.readUnsignedShort());
diff --git a/java/org/apache/tomcat/util/bcel/classfile/Method.java b/java/org/apache/tomcat/util/bcel/classfile/Method.java
index dd6f8cf..e5b4bbc 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/Method.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/Method.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -28,6 +28,7 @@ import org.apache.tomcat.util.bcel.util.BCELComparator;
* for a method in the class. See JVM specification for details.
* A method has access flags, a name, a signature and a number of attributes.
*
+ * @version $Id$
* @author M. Dahm
*/
public final class Method extends FieldOrMethod {
@@ -66,7 +67,7 @@ public final class Method extends FieldOrMethod {
* @throws IOException
* @throws ClassFormatException
*/
- Method(DataInputStream file, ConstantPool constant_pool) throws IOException,
+ Method(DataInput file, ConstantPool constant_pool) throws IOException,
ClassFormatException {
super(file, constant_pool);
}
diff --git a/java/org/apache/tomcat/util/bcel/classfile/PMGClass.java b/java/org/apache/tomcat/util/bcel/classfile/PMGClass.java
index 6ed145b..0ce4de2 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/PMGClass.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/PMGClass.java
@@ -26,6 +26,7 @@ import org.apache.tomcat.util.bcel.Constants;
* This class is derived from Attribute and represents a reference
* to a PMG attribute.
*
+ * @version $Id$
* @author M. Dahm
* @see Attribute
*/
diff --git a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java b/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java
index 7e07109..0d2846d 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotationEntry.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -25,8 +25,9 @@ import org.apache.tomcat.util.bcel.Constants;
/**
* represents one parameter annotation in the parameter annotation table
*
+ * @version $Id: ParameterAnnotationEntry
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public class ParameterAnnotationEntry implements Constants {
@@ -39,7 +40,7 @@ public class ParameterAnnotationEntry implements Constants {
* @param file Input stream
* @throws IOException
*/
- ParameterAnnotationEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
+ ParameterAnnotationEntry(DataInput file, ConstantPool constant_pool) throws IOException {
annotation_table_length = (file.readUnsignedShort());
annotation_table = new AnnotationEntry[annotation_table_length];
for (int i = 0; i < annotation_table_length; i++) {
diff --git a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java b/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
index 82d593f..0d015f8 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/ParameterAnnotations.java
@@ -17,14 +17,15 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
/**
* base class for parameter annotations
*
+ * @version $Id: ParameterAnnotations
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public abstract class ParameterAnnotations extends Attribute {
@@ -41,7 +42,7 @@ public abstract class ParameterAnnotations extends Attribute {
* @param constant_pool Array of constants
*/
ParameterAnnotations(byte parameter_annotation_type, int name_index, int length,
- DataInputStream file, ConstantPool constant_pool) throws IOException {
+ DataInput file, ConstantPool constant_pool) throws IOException {
this(parameter_annotation_type, name_index, length, (ParameterAnnotationEntry[]) null,
constant_pool);
num_parameters = (file.readUnsignedByte());
diff --git a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java b/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java
index f56927c..bb6637b 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleAnnotations.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,8 +26,9 @@ import org.apache.tomcat.util.bcel.Constants;
* represents an annotation that is represented in the class file but is not
* provided to the JVM.
*
+ * @version $Id: RuntimeInvisibleAnnotations
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public class RuntimeInvisibleAnnotations extends Annotations
{
@@ -44,10 +45,10 @@ public class RuntimeInvisibleAnnotations extends Annotations
* Array of constants
*/
RuntimeInvisibleAnnotations(int name_index, int length,
- DataInputStream file, ConstantPool constant_pool)
+ DataInput file, ConstantPool constant_pool)
throws IOException
{
- super(Constants.ATTR_RUNTIME_INVISIBLE_ANNOTATIONS, name_index, length,
+ super(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, length,
file, constant_pool);
}
diff --git a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java b/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
index d7bca29..85b98eb 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/RuntimeInvisibleParameterAnnotations.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,8 +26,9 @@ import org.apache.tomcat.util.bcel.Constants;
* represents a parameter annotation that is represented in the class file
* but is not provided to the JVM.
*
+ * @version $Id: RuntimeInvisibleParameterAnnotations
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
@@ -40,9 +41,9 @@ public class RuntimeInvisibleParameterAnnotations extends ParameterAnnotations {
* @param file Input stream
* @param constant_pool Array of constants
*/
- RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInputStream file,
+ RuntimeInvisibleParameterAnnotations(int name_index, int length, DataInput file,
ConstantPool constant_pool) throws IOException {
- super(Constants.ATTR_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
+ super(Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
constant_pool);
}
diff --git a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleAnnotations.java b/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleAnnotations.java
index dce7814..87e16cb 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleAnnotations.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleAnnotations.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,8 +26,9 @@ import org.apache.tomcat.util.bcel.Constants;
* represents an annotation that is represented in the class file and is
* provided to the JVM.
*
+ * @version $Id: RuntimeVisibleAnnotations
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public class RuntimeVisibleAnnotations extends Annotations
{
@@ -44,7 +45,7 @@ public class RuntimeVisibleAnnotations extends Annotations
* Array of constants
*/
public RuntimeVisibleAnnotations(int name_index, int length,
- DataInputStream file, ConstantPool constant_pool)
+ DataInput file, ConstantPool constant_pool)
throws IOException
{
super(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length,
diff --git a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleParameterAnnotations.java b/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleParameterAnnotations.java
index 0e71df2..286d53b 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleParameterAnnotations.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/RuntimeVisibleParameterAnnotations.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,8 +26,9 @@ import org.apache.tomcat.util.bcel.Constants;
* represents a parameter annotation that is represented in the class file
* and is provided to the JVM.
*
+ * @version $Id: RuntimeVisibleParameterAnnotations
* @author D. Brosius
- * @since 6.0
+ * @since 5.3
*/
public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
@@ -40,7 +41,7 @@ public class RuntimeVisibleParameterAnnotations extends ParameterAnnotations {
* @param file Input stream
* @param constant_pool Array of constants
*/
- RuntimeVisibleParameterAnnotations(int name_index, int length, DataInputStream file,
+ RuntimeVisibleParameterAnnotations(int name_index, int length, DataInput file,
ConstantPool constant_pool) throws IOException {
super(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file,
constant_pool);
diff --git a/java/org/apache/tomcat/util/bcel/classfile/Signature.java b/java/org/apache/tomcat/util/bcel/classfile/Signature.java
index 19b8dc7..134b85f 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/Signature.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/Signature.java
@@ -26,6 +26,7 @@ import org.apache.tomcat.util.bcel.Constants;
* This class is derived from Attribute and represents a reference
* to a GJ attribute.
*
+ * @version $Id$
* @author M. Dahm
* @see Attribute
*/
diff --git a/java/org/apache/tomcat/util/bcel/classfile/SimpleElementValue.java b/java/org/apache/tomcat/util/bcel/classfile/SimpleElementValue.java
index d866193..5b185b7 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/SimpleElementValue.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/SimpleElementValue.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataOutputStream;
+import java.io.DataOutput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -100,7 +100,7 @@ public class SimpleElementValue extends ElementValue
}
@Override
- public void dump(DataOutputStream dos) throws IOException
+ public void dump(DataOutput dos) throws IOException
{
dos.writeByte(type); // u1 kind of value
switch (type)
diff --git a/java/org/apache/tomcat/util/bcel/classfile/SourceFile.java b/java/org/apache/tomcat/util/bcel/classfile/SourceFile.java
index 96b5783..07e3bd0 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/SourceFile.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/SourceFile.java
@@ -28,6 +28,7 @@ import org.apache.tomcat.util.bcel.Constants;
* should appear per classfile. The intention of this class is that it is
* instantiated from the Attribute.readAttribute() method.
*
+ * @version $Id$
* @author M. Dahm
* @see Attribute
*/
diff --git a/java/org/apache/tomcat/util/bcel/classfile/StackMap.java b/java/org/apache/tomcat/util/bcel/classfile/StackMap.java
index 820f8f1..5eb31bb 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/StackMap.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/StackMap.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -31,6 +31,7 @@ import org.apache.tomcat.util.bcel.Constants;
* within the Code attribute of a method. See CLDC specification
* §5.3.1.2
*
+ * @version $Id$
* @author M. Dahm
* @see Code
* @see StackMapEntry
@@ -63,7 +64,7 @@ public final class StackMap extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- StackMap(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ StackMap(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (StackMapEntry[]) null, constant_pool);
map_length = file.readUnsignedShort();
diff --git a/java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java b/java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java
index a40ffda..bdebefb 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/StackMapEntry.java
@@ -17,16 +17,14 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
+import java.io.*;
/**
* This class represents a stack map entry recording the types of
* local variables and the the of stack items at a given byte code offset.
* See CLDC specification §5.3.1.2
*
+ * @version $Id$
* @author M. Dahm
* @see StackMap
* @see StackMapType
@@ -47,7 +45,7 @@ public final class StackMapEntry implements Cloneable, Serializable {
* @param file Input stream
* @throws IOException
*/
- StackMapEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
+ StackMapEntry(DataInput file, ConstantPool constant_pool) throws IOException {
this(file.readShort(), file.readShort(), null, -1, null);
types_of_locals = new StackMapType[number_of_locals];
for (int i = 0; i < number_of_locals; i++) {
diff --git a/java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java b/java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java
index da69e61..ee448f4 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/StackMapTable.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -31,6 +31,7 @@ import org.apache.tomcat.util.bcel.Constants;
* within the Code attribute of a method. See CLDC specification
* §5.3.1.2
*
+ * @version $Id$
* @author M. Dahm
* @see Code
* @see StackMapEntry
@@ -63,7 +64,7 @@ public final class StackMapTable extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- StackMapTable(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ StackMapTable(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (StackMapTableEntry[]) null, constant_pool);
map_length = file.readUnsignedShort();
diff --git a/java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java b/java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java
index 58e28fd..11c8653 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/StackMapTableEntry.java
@@ -17,10 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.Serializable;
+import java.io.*;
import org.apache.tomcat.util.bcel.Constants;
@@ -29,6 +26,7 @@ import org.apache.tomcat.util.bcel.Constants;
* local variables and the the of stack items at a given byte code offset.
* See CLDC specification §5.3.1.2
*
+ * @version $Id$
* @author M. Dahm
* @see StackMap
* @see StackMapType
@@ -50,8 +48,8 @@ public final class StackMapTableEntry implements Cloneable, Serializable {
* @param file Input stream
* @throws IOException
*/
- StackMapTableEntry(DataInputStream file, ConstantPool constant_pool) throws IOException {
- this(file.read(), -1, -1, null, -1, null);
+ StackMapTableEntry(DataInput file, ConstantPool constant_pool) throws IOException {
+ this(file.readUnsignedByte(), -1, -1, null, -1, null);
if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
byte_code_offset_delta = frame_type - Constants.SAME_FRAME;
diff --git a/java/org/apache/tomcat/util/bcel/classfile/StackMapType.java b/java/org/apache/tomcat/util/bcel/classfile/StackMapType.java
index 7c8816e..93d9009 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/StackMapType.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/StackMapType.java
@@ -28,6 +28,7 @@ import org.apache.tomcat.util.bcel.Constants;
* This class represents the type of a local variable or item on stack
* used in the StackMap entries.
*
+ * @version $Id$
* @author M. Dahm
* @see StackMapEntry
* @see StackMap
diff --git a/java/org/apache/tomcat/util/bcel/classfile/Synthetic.java b/java/org/apache/tomcat/util/bcel/classfile/Synthetic.java
index 8ec4b92..0122ecb 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/Synthetic.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/Synthetic.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -31,6 +31,7 @@ import org.apache.tomcat.util.bcel.Constants;
* is intended to be instantiated from the
* Attribute.readAttribute() method.
*
+ * @version $Id$
* @author M. Dahm
* @see Attribute
*/
@@ -62,7 +63,7 @@ public final class Synthetic extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- Synthetic(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ Synthetic(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (byte[]) null, constant_pool);
if (length > 0) {
diff --git a/java/org/apache/tomcat/util/bcel/classfile/Unknown.java b/java/org/apache/tomcat/util/bcel/classfile/Unknown.java
index d61ac0b..11e7d13 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/Unknown.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/Unknown.java
@@ -17,7 +17,7 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInputStream;
+import java.io.DataInput;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -35,6 +35,7 @@ import org.apache.tomcat.util.bcel.Constants;
* org.apache.tomcat.util.bcel.classfile.AttributeReader)">Attribute.addAttributeReader.
*
+ * @version $Id$
* @see org.apache.tomcat.util.bcel.classfile.Attribute
* @see org.apache.tomcat.util.bcel.classfile.AttributeReader
* @author M. Dahm
@@ -73,7 +74,7 @@ public final class Unknown extends Attribute {
* @param constant_pool Array of constants
* @throws IOException
*/
- Unknown(int name_index, int length, DataInputStream file, ConstantPool constant_pool)
+ Unknown(int name_index, int length, DataInput file, ConstantPool constant_pool)
throws IOException {
this(name_index, length, (byte[]) null, constant_pool);
if (length > 0) {
diff --git a/java/org/apache/tomcat/util/bcel/classfile/Utility.java b/java/org/apache/tomcat/util/bcel/classfile/Utility.java
index 75caa96..f83b04a 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/Utility.java
+++ b/java/org/apache/tomcat/util/bcel/classfile/Utility.java
@@ -17,7 +17,6 @@
*/
package org.apache.tomcat.util.bcel.classfile;
-import java.io.DataInput;
import java.io.IOException;
import org.apache.tomcat.util.bcel.Constants;
@@ -26,6 +25,7 @@ import org.apache.tomcat.util.bcel.util.ByteSequence;
/**
* Utility functions that do not really belong to any class in particular.
*
+ * @version $Id$
* @author M. Dahm
*/
public abstract class Utility {
@@ -778,23 +778,4 @@ public abstract class Utility {
}
return buf.toString();
}
-
- static void swallowBootstrapMethods(DataInput file) throws IOException {
- int num_bootstrap_methods = file.readUnsignedShort();
- for (int i = 0; i < num_bootstrap_methods; i++) {
- file.readUnsignedShort(); // Unused bootstrap_method_ref
- int num_bootstrap_args = file.readUnsignedShort();
- for (int j = 0; j < num_bootstrap_args; j++) {
- file.readUnsignedShort(); // Unused bootstrap method argument
- }
- }
- }
-
- static void swallowMethodParameters(DataInput file) throws IOException {
- int parameters_count = file.readUnsignedByte();
- for (int i = 0; i < parameters_count; i++) {
- file.readUnsignedShort(); // Unused name_index
- file.readUnsignedShort(); // Unused access_flags
- }
- }
}
diff --git a/java/org/apache/tomcat/util/bcel/classfile/package.html b/java/org/apache/tomcat/util/bcel/classfile/package.html
index 4a9c4b3..e82c2d9 100644
--- a/java/org/apache/tomcat/util/bcel/classfile/package.html
+++ b/java/org/apache/tomcat/util/bcel/classfile/package.html
@@ -17,6 +17,9 @@
+
diff --git a/java/org/apache/tomcat/util/bcel/util/BCELComparator.java b/java/org/apache/tomcat/util/bcel/util/BCELComparator.java
index 3e92a8d..2d68865 100644
--- a/java/org/apache/tomcat/util/bcel/util/BCELComparator.java
+++ b/java/org/apache/tomcat/util/bcel/util/BCELComparator.java
@@ -21,6 +21,7 @@ package org.apache.tomcat.util.bcel.util;
* Used for BCEL comparison strategy
*
* @author M. Dahm
+ * @version $Id$
* @since 5.2
*/
public interface BCELComparator {
diff --git a/java/org/apache/tomcat/util/bcel/util/ByteSequence.java b/java/org/apache/tomcat/util/bcel/util/ByteSequence.java
index 00b0e5c..e0c8f38 100644
--- a/java/org/apache/tomcat/util/bcel/util/ByteSequence.java
+++ b/java/org/apache/tomcat/util/bcel/util/ByteSequence.java
@@ -25,6 +25,7 @@ import java.io.DataInputStream;
* via the `readByte()' method. This is used to implement a wrapper for the
* Java byte code stream to gain some more readability.
*
+ * @version $Id$
* @author M. Dahm
*/
public final class ByteSequence extends DataInputStream {
diff --git a/java/org/apache/tomcat/util/bcel/util/FastDataInputStream.java b/java/org/apache/tomcat/util/bcel/util/FastDataInputStream.java
new file mode 100644
index 0000000..06dfea5
--- /dev/null
+++ b/java/org/apache/tomcat/util/bcel/util/FastDataInputStream.java
@@ -0,0 +1,345 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tomcat.util.bcel.util;
+
+import java.io.DataInput;
+import java.io.EOFException;
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UTFDataFormatException;
+
+
+/**
+ * Created by xshao on 7/31/14.
+ */
+public class FastDataInputStream extends FilterInputStream implements DataInput {
+ /**
+ * Creates a DataInputStream that uses the specified
+ * underlying InputStream.
+ *
+ * @param in the specified input stream
+ * @throws IOException
+ */
+
+ //Buff
+ private static int defaultBufferSize = 8192;
+ protected volatile byte buf[];
+ protected int cnt;
+ protected int pos;
+
+ //Constructor
+ public FastDataInputStream(InputStream in) {
+ super(in);
+ buf = new byte[defaultBufferSize];
+ }
+
+ public FastDataInputStream(InputStream in, int size) {
+ super(in);
+ if (size <= 0) {
+ throw new IllegalArgumentException("Buffer size <= 0");
+ }
+ buf = new byte[size];
+ }
+
+ public final int read(byte b[]) throws IOException {
+ return this.read(b, 0, b.length);
+ }
+
+ public int read(byte b[], int off, int len)
+ throws IOException
+ {
+ if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
+ throw new IndexOutOfBoundsException();
+ } else if (len == 0) {
+ return 0;
+ }
+
+ int n = 0;
+ for (;;) {
+ int nread = read1(b, off + n, len - n);
+ if (nread <= 0)
+ return (n == 0) ? nread : n;
+ n += nread;
+ if (n >= len)
+ return n;
+ // if not closed but no bytes available, return
+ InputStream input = in;
+ if (input != null && input.available() <= 0)
+ return n;
+ }
+ }
+
+ private int read1(byte[] b, int off, int len) throws IOException {
+ int avail = cnt - pos;
+ if (avail <= 0) {
+ /* If the requested length is at least as large as the buffer, and
+ if there is no mark/reset activity, do not bother to copy the
+ bytes into the local buffer. In this way buffered streams will
+ cascade harmlessly. */
+ if (len >= this.buf.length) {
+ return this.in.read(b, off, len);
+ }
+ fill();
+ avail = cnt - pos;
+ if (avail <= 0) return -1;
+ }
+ int inc = (avail < len) ? avail : len;
+ System.arraycopy(this.buf, pos, b, off, inc);
+ pos += inc;
+ return inc;
+ }
+
+ public final void readFully(byte b[]) throws IOException {
+// System.out.println("readFully");
+
+ readFully(b, 0, b.length);
+ }
+
+ @Override
+ public final void readFully(byte b[], int off, int len) throws IOException {
+ if (len < 0)
+ throw new IndexOutOfBoundsException();
+ int n = 0;
+ while (n < len) {
+ int count = this.read(b, off + n, len - n);
+ if (count < 0)
+ throw new EOFException();
+ n += count;
+ }
+ }
+
+ @Override
+ public boolean readBoolean() throws IOException {
+ if (pos >= cnt) {
+ fill();
+ if (pos >= cnt)
+ throw new EOFException();
+ }
+ int ch = this.buf[pos++] & 0xff;
+ return (ch != 0);
+ }
+
+ public final byte readByte() throws IOException {
+// System.out.println("readByte");
+
+ if (pos >= cnt) {
+ fill();
+ if (pos >= cnt)
+ throw new EOFException();
+ }
+ return this.buf[pos++];
+// int ch = this.buf[pos++] & 0xff;
+// return (byte)(ch);
+ }
+
+ @Override
+ public int readUnsignedByte() throws IOException {
+ if (pos >= cnt) {
+ fill();
+ if (pos >= cnt)
+ throw new EOFException();
+ }
+ int ch = this.buf[pos++] & 0xff;
+ return ch;
+ }
+
+ public final short readShort() throws IOException {
+// System.out.println("readShort");
+
+ if(pos + 1 >= cnt){
+ fill();
+ if(pos + 1 >= cnt) throw new EOFException();
+ }
+ int ch1 = this.buf[pos++] & 0xff;
+ int ch2 = this.buf[pos++] & 0xff;
+ return (short)((ch1 << 8) + (ch2 << 0));
+ }
+
+ public int readUnsignedShort() throws IOException{
+// System.out.println("readUnsignedShort");
+
+ if(pos + 1 >= cnt) {
+ fill();
+ if(pos + 1 >= cnt) throw new EOFException();
+ }
+
+ int ch1 = this.buf[pos++] & 0xff;
+ int ch2 = this.buf[pos++] & 0xff;
+ return (ch1 << 8) + (ch2 << 0);
+ }
+
+ public final char readChar() throws IOException {
+// System.out.println("readChar");
+
+ if(pos + 1 >= cnt) {
+ fill();
+ if(pos + 1 >= cnt) throw new EOFException();
+ }
+ int ch1 = this.buf[pos++] & 0xff;
+ int ch2 = this.buf[pos++] & 0xff;
+ return (char)((ch1 << 8) + (ch2 << 0));
+ }
+
+ public final int readInt() throws IOException {
+// System.out.println("readInt");
+
+ if(pos + 3 >= cnt){
+ fill();
+ if(pos + 3 >= cnt) throw new EOFException();
+ }
+ int ch1 = this.buf[pos++] & 0xff;
+ int ch2 = this.buf[pos++] & 0xff;
+ int ch3 = this.buf[pos++] & 0xff;
+ int ch4 = this.buf[pos++] & 0xff;
+ return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
+ }
+
+ private byte readBuffer[] = new byte[8];
+
+ public final long readLong() throws IOException {
+ readFully(readBuffer, 0, 8);
+ return (((long)readBuffer[0] << 56) +
+ ((long)(readBuffer[1] & 255) << 48) +
+ ((long)(readBuffer[2] & 255) << 40) +
+ ((long)(readBuffer[3] & 255) << 32) +
+ ((long)(readBuffer[4] & 255) << 24) +
+ ((readBuffer[5] & 255) << 16) +
+ ((readBuffer[6] & 255) << 8) +
+ ((readBuffer[7] & 255) << 0));
+ }
+
+ public final float readFloat() throws IOException {
+ return Float.intBitsToFloat(readInt());
+ }
+
+ @Override
+ public double readDouble() throws IOException {
+ return Double.longBitsToDouble(readLong());
+ }
+
+ public final String readUTF() throws IOException {
+// System.out.println("readUTF");
+
+ return readUTF(this);
+ }
+
+ private byte bytearr[] = new byte[80];
+ private char chararr[] = new char[80];
+
+ public final String readUTF(DataInput in) throws IOException {
+ int utflen = this.readUnsignedShort();
+ byte[] bytearr = null;
+ char[] chararr = null;
+ if (in instanceof FastDataInputStream) {
+ FastDataInputStream dis = (FastDataInputStream)in;
+ if (dis.bytearr.length < utflen){
+ dis.bytearr = new byte[utflen*2];
+ dis.chararr = new char[utflen*2];
+ }
+ chararr = dis.chararr;
+ bytearr = dis.bytearr;
+ } else {
+ bytearr = new byte[utflen];
+ chararr = new char[utflen];
+ }
+
+ int c, char2, char3;
+ int count = 0;
+ int chararr_count=0;
+
+ this.readFully(bytearr, 0, utflen);
+
+ while (count < utflen) {
+ c = (int) bytearr[count] & 0xff;
+ if (c > 127) break;
+ count++;
+ chararr[chararr_count++]=(char)c;
+ }
+
+ while (count < utflen) {
+ c = (int) bytearr[count] & 0xff;
+ switch (c >> 4) {
+ case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
+ /* 0xxxxxxx*/
+ count++;
+ chararr[chararr_count++]=(char)c;
+ break;
+ case 12: case 13:
+ /* 110x xxxx 10xx xxxx*/
+ count += 2;
+ if (count > utflen)
+ throw new UTFDataFormatException(
+ "malformed input: partial character at end");
+ char2 = (int) bytearr[count-1];
+ if ((char2 & 0xC0) != 0x80)
+ throw new UTFDataFormatException(
+ "malformed input around byte " + count);
+ chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
+ (char2 & 0x3F));
+ break;
+ case 14:
+ /* 1110 xxxx 10xx xxxx 10xx xxxx */
+ count += 3;
+ if (count > utflen)
+ throw new UTFDataFormatException(
+ "malformed input: partial character at end");
+ char2 = (int) bytearr[count-2];
+ char3 = (int) bytearr[count-1];
+ if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
+ throw new UTFDataFormatException(
+ "malformed input around byte " + (count-1));
+ chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
+ ((char2 & 0x3F) << 6) |
+ ((char3 & 0x3F) << 0));
+ break;
+ default:
+ /* 10xx xxxx, 1111 xxxx */
+ throw new UTFDataFormatException(
+ "malformed input around byte " + count);
+ }
+ }
+ // The number of chars produced may be less than utflen
+ return new String(chararr, 0, chararr_count);
+ }
+
+ private void fill() throws IOException {
+// System.out.println("fill");
+ int remain = 0;
+ if(pos < cnt){
+ remain = cnt - pos;
+ System.arraycopy(buf, cnt - remain, buf, 0, remain);
+ }
+ pos = 0;
+ int n = this.in.read(buf, remain, defaultBufferSize - remain);
+ cnt = pos + n + remain;
+ }
+
+// unimplemented
+ @Override
+ public int skipBytes(int n) throws IOException {
+ // TODO Auto-generated method stub
+ throw new IOException();
+ }
+
+ @Override
+ public String readLine() throws IOException {
+ // TODO Auto-generated method stub
+ throw new IOException();
+ }
+}
diff --git a/java/org/apache/tomcat/util/bcel/util/package.html b/java/org/apache/tomcat/util/bcel/util/package.html
index f3447bd..01618ec 100644
--- a/java/org/apache/tomcat/util/bcel/util/package.html
+++ b/java/org/apache/tomcat/util/bcel/util/package.html
@@ -17,11 +17,14 @@
+
This package contains utility classes for the
-Byte Code Engineering
+Byte Code Engineering
Library, namely:
diff --git a/patches/fixCache/patch b/patches/fixCache/patch
new file mode 100644
index 0000000..3f3d3aa
--- /dev/null
+++ b/patches/fixCache/patch
@@ -0,0 +1,192 @@
+diff --git a/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java b/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
+index f467848..78e892d 100644
+--- a/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
++++ b/java/org/apache/tomcat/util/bcel/classfile/ConstantUtf8.java
+@@ -34,6 +34,9 @@ import org.apache.tomcat.util.bcel.Constants;
+ * @see Constant
+ */
+ public final class ConstantUtf8 extends Constant {
++
++ //switch for cache
++ public static boolean hasCache = true;
+
+ private static final long serialVersionUID = 8119001312020421976L;
+ private final String bytes;
+@@ -43,26 +46,29 @@ public final class ConstantUtf8 extends Constant {
+ private static HashMap cache;
+
+ private static synchronized ConstantUtf8 getCachedInstance(String s) {
+- if (s.length() > 200) {
+- return new ConstantUtf8(s);
++ if(hasCache){
++ if (s.length() > 200) {
++ return new ConstantUtf8(s);
++ }
++ if (cache == null) {
++ cache = new LinkedHashMap(INITIAL_CACHE_CAPACITY, 0.75f, true) {
++ private static final long serialVersionUID = 1L;
++
++ @Override
++ protected boolean removeEldestEntry(Map.Entry eldest) {
++ return size() > MAX_CACHE_ENTRIES;
++ }
++ };
++ }
++ ConstantUtf8 result = cache.get(s);
++ if (result != null) {
++ return result;
++ }
++ result = new ConstantUtf8(s);
++ cache.put(s, result);
++ return result;
+ }
+- if (cache == null) {
+- cache = new LinkedHashMap(INITIAL_CACHE_CAPACITY, 0.75f, true) {
+- private static final long serialVersionUID = 1L;
+-
+- @Override
+- protected boolean removeEldestEntry(Map.Entry eldest) {
+- return size() > MAX_CACHE_ENTRIES;
+- }
+- };
+- }
+- ConstantUtf8 result = cache.get(s);
+- if (result != null) {
+- return result;
+- }
+- result = new ConstantUtf8(s);
+- cache.put(s, result);
+- return result;
++ else return new ConstantUtf8(s);
+ }
+
+ private static ConstantUtf8 getInstance(String s) {
+diff --git a/test/org/apache/tomcat/util/bcel/classfile/test/TestConstantUtf8.java b/test/org/apache/tomcat/util/bcel/classfile/test/TestConstantUtf8.java
+new file mode 100644
+index 0000000..930b697
+--- /dev/null
++++ b/test/org/apache/tomcat/util/bcel/classfile/test/TestConstantUtf8.java
+@@ -0,0 +1,122 @@
++/*
++ * Licensed to the Apache Software Foundation (ASF) under one or more
++ * contributor license agreements. See the NOTICE file distributed with
++ * this work for additional information regarding copyright ownership.
++ * The ASF licenses this file to You under the Apache License, Version 2.0
++ * (the "License"); you may not use this file except in compliance with
++ * the License. You may obtain a copy of the License at
++ *
++ * http://www.apache.org/licenses/LICENSE-2.0
++ *
++ * Unless required by applicable law or agreed to in writing, software
++ * distributed under the License is distributed on an "AS IS" BASIS,
++ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
++ * See the License for the specific language governing permissions and
++ * limitations under the License.
++ */
++
++package org.apache.tomcat.util.bcel.classfile.test;
++
++import java.io.File;
++import java.io.IOException;
++import java.io.InputStream;
++import java.net.URL;
++
++import org.apache.tomcat.util.bcel.classfile.ClassParser;
++import org.apache.tomcat.util.bcel.classfile.ConstantUtf8;
++import org.apache.tomcat.util.scan.Jar;
++import org.apache.tomcat.util.scan.JarFactory;
++import org.junit.Test;
++
++public class TestConstantUtf8 {
++ public static final int WARMUP = 100;
++
++ long sumCache = 0;
++ long sumNoCache = 0;
++
++ @Test
++ public void testContantUtf8() throws IOException{
++ String str = System.getProperty("java.class.path");
++ str = str.replace('\\', '/');
++ String paths[] = str.split(";");
++ //warm up
++ doWarmUp(paths);
++ //cost without cache
++ countNoCache(paths);
++ //cost with cache
++ countCache(paths);
++ System.out.println("HasCache:" + sumCache);
++ System.out.println("NoCache:" + sumNoCache);
++
++ }
++
++ //warm up
++ public void doWarmUp(String[] paths) throws IOException{
++ for(String path:paths){
++ File file = new File(path);
++ recurCache(file, true);
++ recurCache(file, false);
++ }
++ }
++
++ //with cache
++ public void countCache(String[] paths) throws IOException{
++ boolean hasCache = true;
++ for(String path : paths){
++ File file = new File(path);
++ sumCache += recurCache(file, hasCache);
++ }
++ }
++
++ //without cache
++ public void countNoCache(String[] paths) throws IOException{
++ boolean hasCache = false;
++ for(String path : paths){
++ File file = new File(path);
++ sumNoCache += recurCache(file, hasCache);
++ }
++ }
++
++ //scan jars. "hasCache" indicates the parse model,
++ //"true" means use cache, "false means without cache.
++ public long recurCache(File file, boolean hasCache) throws IOException{
++ String uri = file.toURI().toString();
++ if(uri.endsWith(".jar")){
++ URL jarUrl = new URL("jar:" + uri + "!/");
++ long span = doProcess(jarUrl, hasCache);
++ return span;
++ }
++ else if(file.isDirectory()){
++ for(File var : file.listFiles()){
++ recurCache(var, hasCache);
++ }
++ return 0;
++ }
++ else return 0;
++ }
++
++ //parse & count the cost
++ public static long doProcess(URL jarUrl, boolean hasCache) throws IOException{
++ ConstantUtf8.hasCache = hasCache;
++ long span = 0;
++ Jar jar = null;
++ jar = JarFactory.newInstance(jarUrl);
++ jar.nextEntry();
++ String entryName = jar.getEntryName();
++ while (entryName != null) {
++ //Get ".class" entries
++ if (entryName.endsWith(".class")) {
++ InputStream di = jar.getEntryInputStream();
++ ClassParser parser = new ClassParser(di, null);
++ long start = System.currentTimeMillis();
++ parser.parse();
++ long end = System.currentTimeMillis();
++ span += (end - start);
++
++ }
++ jar.nextEntry();
++ entryName = jar.getEntryName();
++ }
++ return span;
++ }
++}
+\ No newline at end of file
diff --git a/test/org/apache/tomcat/util/bcel/test/TestFastDataInputStream.java b/test/org/apache/tomcat/util/bcel/test/TestFastDataInputStream.java
new file mode 100644
index 0000000..6f43123
--- /dev/null
+++ b/test/org/apache/tomcat/util/bcel/test/TestFastDataInputStream.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tomcat.util.bcel.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.tomcat.util.bcel.classfile.ClassParser;
+import org.apache.tomcat.util.scan.Jar;
+import org.apache.tomcat.util.scan.JarFactory;
+import org.junit.Test;
+
+public class TestFastDataInputStream {
+ //counter
+ long sumOrig = 0;
+ long sumFDIS = 0;
+
+ @Test
+ public void testFDIS() throws IOException{
+ String str = System.getProperty("java.class.path");
+ str = str.replace('\\', '/');
+ String paths[] = str.split(";");
+ //warm up
+ doWarmUp(paths);
+ //cost without cache
+ countWithFDIS(paths);
+ //cost with cache
+ countOrig(paths);
+ System.out.println("=====lots of jar files=====");
+ System.out.println("DataInputStream: " + sumOrig);
+ System.out.println("FastDataInputStream: " + sumFDIS);
+ sumOrig = 0;
+ sumFDIS = 0;
+ countFewWithFDIS(paths);
+ countFewOrig(paths);
+ System.out.println("=====few jar files=====");
+ System.out.println("DataInputStream: " + sumOrig);
+ System.out.println("FastDataInputStream: " + sumFDIS);
+ }
+
+ //warm up
+ public void doWarmUp(String[] paths) throws IOException{
+ for(String path:paths){
+ File file = new File(path);
+ scanRecur(file, true);
+ scanRecur(file, false);
+ }
+ }
+
+ //normal scan with DataInputStream
+ public void countOrig(String[] paths) throws IOException{
+ boolean isFDIS = false;
+ for(String path : paths){
+ File file = new File(path);
+ sumOrig += scanRecur(file, isFDIS);
+ }
+ }
+
+ //normal scan with DataInputStream & few "jar" files
+ public void countFewOrig(String[] paths) throws IOException{
+ boolean isFDIS = false;
+ for(String path : paths){
+ if(path.endsWith(".jar")){
+ File file = new File(path);
+ sumOrig += scanFew(file, isFDIS);
+ break;
+ }
+ }
+ }
+
+ //use FastDataInputStream for "jar" files
+ public void countWithFDIS(String[] paths) throws IOException{
+ boolean isFDIS = true;
+ for(String path : paths){
+ File file = new File(path);
+ sumFDIS += scanRecur(file, isFDIS);
+ }
+ }
+
+ //use FastDataInputStream & one "jar" file
+ public void countFewWithFDIS(String[] paths) throws IOException{
+ boolean isFDIS = true;
+ for(String path : paths){
+ if(path.endsWith(".jar")){
+ File file = new File(path);
+ sumFDIS += scanFew(file, isFDIS);
+ break;
+ }
+ }
+ }
+
+ //scan jars recursively, so that the number of jar is big.
+ //"isFDIS" indicates the parse model,
+ //"true" means use "FastDataInputStream", "false means use "DataInputStream".
+ public long scanRecur(File file, boolean isFDIS) throws IOException{
+ String uri = file.toURI().toString();
+ if(uri.endsWith(".jar")){
+ URL jarUrl = new URL("jar:" + uri + "!/");
+ long span = doProcess(jarUrl, isFDIS);
+ return span;
+ }
+ else if(file.isDirectory()){
+ for(File var : file.listFiles()){
+ scanRecur(var, isFDIS);
+ }
+ return 0;
+ }
+ else return 0;
+ }
+
+ //scan few "jar" files
+ public long scanFew(File file, boolean isFDIS) throws IOException{
+ String uri = file.toURI().toString();
+ if(uri.endsWith(".jar")){
+ URL jarUrl = new URL("jar:" + uri + "!/");
+ long span = doProcess(jarUrl, isFDIS);
+ return span;
+ }
+ else return 0;
+ }
+
+ //parse & count the cost
+ public static long doProcess(URL jarUrl, boolean isFDIS) throws IOException{
+ ClassParser.isFDIS = isFDIS;
+ long span = 0;
+ Jar jar = null;
+ jar = JarFactory.newInstance(jarUrl);
+ jar.nextEntry();
+ String entryName = jar.getEntryName();
+ while (entryName != null) {
+ //Get ".class" entries
+ if (entryName.endsWith(".class")) {
+ InputStream di = jar.getEntryInputStream();
+ ClassParser parser = new ClassParser(di, null);
+ long start = System.currentTimeMillis();
+ parser.parse();
+ long end = System.currentTimeMillis();
+ span += (end - start);
+
+ }
+ jar.nextEntry();
+ entryName = jar.getEntryName();
+ }
+ return span;
+ }
+}