();
- 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++)
--- a/classfile/LineNumber.java
+++ a/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
*/
@@ -45,6 +46,10 @@ public final class LineNumber implements Cloneable, Serializable {
LineNumber(DataInput file) throws IOException {
this(file.readUnsignedShort(), file.readUnsignedShort());
}
+
+ public static void skip(DataInput file) throws IOException{
+ file.skipBytes(4);
+ }
/**
--- a/classfile/LineNumberTable.java
+++ a/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());
@@ -68,6 +69,15 @@ public final class LineNumberTable extends Attribute {
line_number_table[i] = new LineNumber(file);
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ int line_number_table_length = (file.readUnsignedShort());
+ for (int i = 0; i < line_number_table_length; i++) {
+ LineNumber.skip(file);
+ }
+
+ }
/**
--- a/classfile/LocalVariable.java
+++ a/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
*/
@@ -53,6 +54,10 @@ public final class LocalVariable implements Constants, Cloneable, Serializable {
this(file.readUnsignedShort(), file.readUnsignedShort(), file.readUnsignedShort(), file
.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
}
+
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
+ file.skipBytes(10);
+ }
/**
--- a/classfile/LocalVariableTable.java
+++ a/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());
@@ -67,6 +68,14 @@ public class LocalVariableTable extends Attribute {
local_variable_table[i] = new LocalVariable(file, constant_pool);
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ int local_variable_table_length = (file.readUnsignedShort());
+ for (int i = 0; i < local_variable_table_length; i++) {
+ LocalVariable.skip(file, constant_pool);
+ }
+ }
/**
--- a/classfile/LocalVariableTypeTable.java
+++ a/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());
@@ -70,6 +70,15 @@ private int local_variable_type_table_length; // Table of local
for(int i=0; i < local_variable_type_table_length; i++)
local_variable_type_table[i] = new LocalVariable(dis, cpool);
}
+
+ public static void skip(int nameIdx, int len, DataInput dis,ConstantPool cpool) throws IOException {
+ int local_variable_type_table_length = (dis.readUnsignedShort());
+ for(int i=0; i < local_variable_type_table_length; i++){
+ LocalVariable.skip(dis, cpool);
+ }
+
+
+ }
public final void setLocalVariableTable(LocalVariable[] local_variable_table)
{
--- a/classfile/Method.java
+++ a/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,10 +67,15 @@ 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);
}
+
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException,
+ ClassFormatException {
+ FieldOrMethod.skip(file, constant_pool);
+ }
/**
--- a/classfile/PMGClass.java
+++ a/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
*/
@@ -47,6 +48,11 @@ public final class PMGClass extends Attribute {
throws IOException {
this(name_index, length, file.readUnsignedShort(), file.readUnsignedShort(), constant_pool);
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ file.skipBytes(4);
+ }
/**
--- a/classfile/ParameterAnnotationEntry.java
+++ a/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++) {
@@ -47,4 +48,10 @@ public class ParameterAnnotationEntry implements Constants {
}
}
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
+ int annotation_table_length = (file.readUnsignedShort());
+ for (int i = 0; i < annotation_table_length; i++) {
+ AnnotationEntry.skip(file, constant_pool);
+ }
+ }
}
--- a/classfile/ParameterAnnotations.java
+++ a/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());
@@ -50,6 +51,14 @@ public abstract class ParameterAnnotations extends Attribute {
parameter_annotation_table[i] = new ParameterAnnotationEntry(file, constant_pool);
}
}
+
+ public static void skip(byte parameter_annotation_type, int name_index, int length,
+ DataInput file, ConstantPool constant_pool) throws IOException {
+ int num_parameters = (file.readUnsignedByte());
+ for (int i = 0; i < num_parameters; i++) {
+ ParameterAnnotationEntry.skip(file, constant_pool);
+ }
+ }
/**
--- a/classfile/RuntimeInvisibleAnnotations.java
+++ a/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,12 +45,20 @@ 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);
}
+
+ public static void skip(int name_index, int length,
+ DataInput file, ConstantPool constant_pool)
+ throws IOException
+ {
+ Annotations.skip(Constants.ATTR_RUNTIMEIN_VISIBLE_ANNOTATIONS, name_index, length,
+ file, constant_pool);
+ }
/**
* @return deep copy of this attribute
--- a/classfile/RuntimeInvisibleParameterAnnotations.java
+++ a/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,11 +41,16 @@ 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);
}
+
+ public static void skip(int name_index, int length, DataInput file,
+ ConstantPool constant_pool) throws IOException {
+ ParameterAnnotations.skip(Constants.ATTR_RUNTIMEIN_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
+ }
/**
--- a/classfile/RuntimeVisibleAnnotations.java
+++ a/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,12 +45,19 @@ 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,
file, constant_pool);
}
+
+ public static void skip(int name_index, int length,
+ DataInput file, ConstantPool constant_pool)
+ throws IOException
+ {
+ Annotations.skip(Constants.ATTR_RUNTIME_VISIBLE_ANNOTATIONS, name_index, length, file, constant_pool);
+ }
/**
* @return deep copy of this attribute
--- a/classfile/RuntimeVisibleParameterAnnotations.java
+++ a/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,11 +41,16 @@ 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);
}
+
+ public static void skip(int name_index, int length, DataInput file,
+ ConstantPool constant_pool) throws IOException {
+ ParameterAnnotations.skip(Constants.ATTR_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS, name_index, length, file, constant_pool);
+ }
/**
--- a/classfile/Signature.java
+++ a/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
*/
@@ -47,6 +48,11 @@ public final class Signature extends Attribute {
throws IOException {
this(name_index, length, file.readUnsignedShort(), constant_pool);
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ file.skipBytes(2);
+ }
/**
--- a/classfile/SimpleElementValue.java
+++ a/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)
--- a/classfile/SourceFile.java
+++ a/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
*/
@@ -49,6 +50,11 @@ public final class SourceFile extends Attribute {
throws IOException {
this(name_index, length, file.readUnsignedShort(), constant_pool);
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ file.skipBytes(2);
+ }
/**
--- a/classfile/StackMap.java
+++ a/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();
@@ -72,6 +73,14 @@ public final class StackMap extends Attribute {
map[i] = new StackMapEntry(file, constant_pool);
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ int map_length = file.readUnsignedShort();
+ for (int i = 0; i < map_length; i++) {
+ StackMapEntry.skip(file, constant_pool);
+ }
+ }
/**
--- a/classfile/StackMapEntry.java
+++ a/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++) {
@@ -59,6 +57,19 @@ public final class StackMapEntry implements Cloneable, Serializable {
types_of_stack_items[i] = new StackMapType(file, constant_pool);
}
}
+
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
+// int byte_code_offset = file.readShort();
+ file.skipBytes(2);
+ int number_of_locals = file.readShort();
+ for (int i = 0; i < number_of_locals; i++) {
+ StackMapType.skip(file, constant_pool);
+ }
+ int number_of_stack_items = file.readShort();
+ for (int i = 0; i < number_of_stack_items; i++) {
+ StackMapType.skip(file, constant_pool);
+ }
+ }
public StackMapEntry(int byte_code_offset, int number_of_locals,
--- a/classfile/StackMapTable.java
+++ a/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();
@@ -72,6 +73,14 @@ public final class StackMapTable extends Attribute {
map[i] = new StackMapTableEntry(file, constant_pool);
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ int map_length = file.readUnsignedShort();
+ for (int i = 0; i < map_length; i++) {
+ StackMapTableEntry.skip(file, constant_pool);
+ }
+ }
/**
--- a/classfile/StackMapTableEntry.java
+++ a/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;
@@ -93,6 +91,40 @@ public final class StackMapTableEntry implements Cloneable, Serializable {
throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
}
}
+
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
+ int frame_type = file.readUnsignedByte();
+ if (frame_type >= Constants.SAME_FRAME && frame_type <= Constants.SAME_FRAME_MAX) {
+ }else if(frame_type >= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME && frame_type <= Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_MAX){
+ StackMapType.skip(file, constant_pool);
+ }else if (frame_type == Constants.SAME_LOCALS_1_STACK_ITEM_FRAME_EXTENDED) {
+ file.skipBytes(2);
+ StackMapType.skip(file, constant_pool);
+ }else if (frame_type >= Constants.CHOP_FRAME && frame_type <= Constants.CHOP_FRAME_MAX){
+ file.skipBytes(2);
+ }else if (frame_type == Constants.SAME_FRAME_EXTENDED) {
+ file.skipBytes(2);
+ }else if (frame_type >= Constants.APPEND_FRAME && frame_type <= Constants.APPEND_FRAME_MAX) {
+ file.skipBytes(2);
+ int number_of_locals = frame_type - 251;
+ for (int i = 0; i < number_of_locals; i++) {
+ StackMapType.skip(file, constant_pool);
+ }
+ }else if (frame_type == Constants.FULL_FRAME) {
+ file.skipBytes(2);
+ int number_of_locals = file.readShort();
+ for (int i = 0; i < number_of_locals; i++) {
+ StackMapType.skip(file, constant_pool);
+ }
+ int number_of_stack_items = file.readShort();
+ for (int i = 0; i < number_of_stack_items; i++) {
+ StackMapType.skip(file, constant_pool);
+ }
+ }else {
+ /* Can't happen */
+ throw new ClassFormatException ("Invalid frame type found while parsing stack map table: " + frame_type);
+ }
+ }
public StackMapTableEntry(int tag, int byte_code_offset_delta, int number_of_locals,
--- a/classfile/StackMapType.java
+++ a/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
@@ -54,6 +55,14 @@ public final class StackMapType implements Cloneable, Serializable {
}
setConstantPool(constant_pool);
}
+
+ // logic may be false??????????????????????????????????????
+ public static void skip(DataInput file, ConstantPool constant_pool) throws IOException {
+ byte type = file.readByte();
+ if ((type == Constants.ITEM_Object) || (type == Constants.ITEM_NewObject)) {
+ file.skipBytes(2);
+ }
+ }
/**
--- a/classfile/Synthetic.java
+++ a/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) {
@@ -71,6 +72,14 @@ public final class Synthetic extends Attribute {
System.err.println("Synthetic attribute with length > 0");
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ if(length > 0){
+ file.skipBytes(length);
+ System.err.println("Synthetic attribute with length > 0");
+ }
+ }
/**
--- a/classfile/Unknown.java
+++ a/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) {
@@ -81,6 +82,12 @@ public final class Unknown extends Attribute {
file.readFully(bytes);
}
}
+
+ public static void skip(int name_index, int length, DataInput file, ConstantPool constant_pool)
+ throws IOException {
+ if(length > 0) file.skipBytes(length);
+
+ }
/**
--- a/classfile/Utility.java
+++ a/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
- }
- }
}
--- a/classfile/package.html
+++ a/classfile/package.html
@@ -17,6 +17,9 @@
+
--- a/util/BCELComparator.java
+++ a/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 {
--- a/util/ByteSequence.java
+++ a/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 {
--- a/util/FastDataInputStream.java
+++ a/util/FastDataInputStream.java
@@ -0,0 +1,372 @@
+/*
+ * 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 {
+ int avail = cnt - pos;
+ // total skipped
+ int total = 0;
+ // current skipped
+ int cur = 0;
+ 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. */
+ while ((total 0)) {
+ total += cur;
+ }
+ fill();
+ return total;
+ }
+ //num in the buffer is not enough
+ if(n > avail){
+ pos += avail;
+ total += avail;
+ while ((total 0)) {
+ total += cur;
+ }
+ fill();
+ return total;
+ }
+ //num in the buffer is
+ pos += n;
+ return n;
+ }
+
+ @Override
+ public String readLine() throws IOException {
+ // TODO Auto-generated method stub
+ throw new IOException();
+ }
+}