Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

UTF
Class Utf8  view Utf8 download Utf8.java

java.lang.Object
  extended byUTF.Utf8
All Implemented Interfaces:
Clazz.jq_ClassFileConstants

public class Utf8
extends java.lang.Object
implements Clazz.jq_ClassFileConstants

Version:
$Id: Utf8.java,v 1.17 2003/05/23 21:10:56 joewhaley Exp $

Nested Class Summary
 class Utf8.MethodDescriptorIterator
           
 
Field Summary
(package private) static boolean ALLOW_NORMAL_UTF8
          Set fromUtf8 to not throw an exception when given a normal utf8 byte array.
(package private) static boolean ALLOW_PSEUDO_UTF8
          Set fromUtf8 to not throw an exception when given a pseudo utf8 byte array.
static Utf8 BOOLEAN_DESC
           
static Utf8 BYTE_DESC
           
private  java.lang.String cache
           
static int[][] chains
           
static Utf8 CHAR_DESC
           
private  byte[] data
           
static boolean DEBUG
           
static Utf8 DOUBLE_DESC
           
static Utf8 FLOAT_DESC
           
private  int hash
           
static Utf8 INT_DESC
           
static Utf8 LONG_DESC
           
static boolean NO_NEW
           
static Utf8 SHORT_DESC
           
static int size
           
static int STARTING_CHAIN_SIZE
           
static int STARTING_HASH_SIZE
           
static int STARTING_TABLE_SIZE
           
(package private) static boolean STRICTLY_CHECK_FORMAT
          Strictly check the format of the utf8/pseudo-utf8 byte array in fromUtf8.
static Utf8[] table
           
static boolean TRACE
           
static boolean USE_CACHE
           
static Utf8 VOID_DESC
           
(package private) static boolean WRITE_PSEUDO_UTF8
          Set toUtf8 to write in pseudo-utf8 (rather than normal utf8).
 
Fields inherited from interface Clazz.jq_ClassFileConstants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_Long, CONSTANT_MethodRef, CONSTANT_NameAndType, CONSTANT_ResolvedClass, CONSTANT_ResolvedIFieldRef, CONSTANT_ResolvedIMethodRef, CONSTANT_ResolvedSFieldRef, CONSTANT_ResolvedSMethodRef, CONSTANT_String, CONSTANT_Utf8, CONSUME_STACK, ILLEGAL_OPCODE, ILLEGAL_TYPE, jbc_AALOAD, jbc_AASTORE, jbc_ACONST_NULL, jbc_ALOAD, jbc_ALOAD_0, jbc_ALOAD_1, jbc_ALOAD_2, jbc_ALOAD_3, jbc_ANEWARRAY, jbc_ARETURN, jbc_ARRAYLENGTH, jbc_ASTORE, jbc_ASTORE_0, jbc_ASTORE_1, jbc_ASTORE_2, jbc_ASTORE_3, jbc_ATHROW, jbc_BALOAD, jbc_BASTORE, jbc_BIPUSH, jbc_BREAKPOINT, jbc_CALOAD, jbc_CASTORE, jbc_CHECKCAST, jbc_D2F, jbc_D2I, jbc_D2L, jbc_DADD, jbc_DALOAD, jbc_DASTORE, jbc_DCMPG, jbc_DCMPL, jbc_DCONST_0, jbc_DCONST_1, jbc_DDIV, jbc_DLOAD, jbc_DLOAD_0, jbc_DLOAD_1, jbc_DLOAD_2, jbc_DLOAD_3, jbc_DMUL, jbc_DNEG, jbc_DREM, jbc_DRETURN, jbc_DSTORE, jbc_DSTORE_0, jbc_DSTORE_1, jbc_DSTORE_2, jbc_DSTORE_3, jbc_DSUB, jbc_DUP, jbc_DUP_X1, jbc_DUP_X2, jbc_DUP2, jbc_DUP2_X1, jbc_DUP2_X2, jbc_F2D, jbc_F2I, jbc_F2L, jbc_FADD, jbc_FALOAD, jbc_FASTORE, jbc_FCMPG, jbc_FCMPL, jbc_FCONST_0, jbc_FCONST_1, jbc_FCONST_2, jbc_FDIV, jbc_FLOAD, jbc_FLOAD_0, jbc_FLOAD_1, jbc_FLOAD_2, jbc_FLOAD_3, jbc_FMUL, jbc_FNEG, jbc_FREM, jbc_FRETURN, jbc_FSTORE, jbc_FSTORE_0, jbc_FSTORE_1, jbc_FSTORE_2, jbc_FSTORE_3, jbc_FSUB, jbc_GETFIELD, jbc_GETSTATIC, jbc_GOTO, jbc_GOTO_W, jbc_I2B, jbc_I2C, jbc_I2D, jbc_I2F, jbc_I2L, jbc_I2S, jbc_IADD, jbc_IALOAD, jbc_IAND, jbc_IASTORE, jbc_ICONST_0, jbc_ICONST_1, jbc_ICONST_2, jbc_ICONST_3, jbc_ICONST_4, jbc_ICONST_5, jbc_ICONST_M1, jbc_IDIV, jbc_IF_ACMPEQ, jbc_IF_ACMPNE, jbc_IF_ICMPEQ, jbc_IF_ICMPGE, jbc_IF_ICMPGT, jbc_IF_ICMPLE, jbc_IF_ICMPLT, jbc_IF_ICMPNE, jbc_IFEQ, jbc_IFGE, jbc_IFGT, jbc_IFLE, jbc_IFLT, jbc_IFNE, jbc_IFNONNULL, jbc_IFNULL, jbc_IINC, jbc_ILOAD, jbc_ILOAD_0, jbc_ILOAD_1, jbc_ILOAD_2, jbc_ILOAD_3, jbc_IMUL, jbc_INEG, jbc_INSTANCEOF, jbc_INT2BYTE, jbc_INT2CHAR, jbc_INT2SHORT, jbc_INVOKEINTERFACE, jbc_INVOKENONVIRTUAL, jbc_INVOKESPECIAL, jbc_INVOKESTATIC, jbc_INVOKEVIRTUAL, jbc_IOR, jbc_IREM, jbc_IRETURN, jbc_ISHL, jbc_ISHR, jbc_ISTORE, jbc_ISTORE_0, jbc_ISTORE_1, jbc_ISTORE_2, jbc_ISTORE_3, jbc_ISUB, jbc_IUSHR, jbc_IXOR, jbc_JSR, jbc_JSR_W, jbc_L2D, jbc_L2F, jbc_L2I, jbc_LADD, jbc_LALOAD, jbc_LAND, jbc_LASTORE, jbc_LCMP, jbc_LCONST_0, jbc_LCONST_1, jbc_LDC, jbc_LDC_W, jbc_LDC2_W, jbc_LDIV, jbc_LLOAD, jbc_LLOAD_0, jbc_LLOAD_1, jbc_LLOAD_2, jbc_LLOAD_3, jbc_LMUL, jbc_LNEG, jbc_LOOKUPSWITCH, jbc_LOR, jbc_LREM, jbc_LRETURN, jbc_LSHL, jbc_LSHR, jbc_LSTORE, jbc_LSTORE_0, jbc_LSTORE_1, jbc_LSTORE_2, jbc_LSTORE_3, jbc_LSUB, jbc_LUSHR, jbc_LXOR, jbc_MONITORENTER, jbc_MONITOREXIT, jbc_MULTIANEWARRAY, jbc_NEW, jbc_NEWARRAY, jbc_NOP, jbc_POP, jbc_POP2, jbc_PUTFIELD, jbc_PUTSTATIC, jbc_RET, jbc_RETURN, jbc_SALOAD, jbc_SASTORE, jbc_SIPUSH, jbc_SWAP, jbc_TABLESWITCH, jbc_WIDE, NO_OF_OPERANDS, OPCODE_NAMES, PRODUCE_STACK, RESERVED, STATE_CLSINITERROR, STATE_CLSINITIALIZED, STATE_CLSINITIALIZING, STATE_CLSINITRUNNING, STATE_COMPILED, STATE_COMPILING, STATE_LOADED, STATE_LOADERROR, STATE_LOADING1, STATE_LOADING2, STATE_LOADING3, STATE_PREPARED, STATE_PREPARING, STATE_SFINITIALIZED, STATE_SFINITIALIZING, STATE_UNLOADED, STATE_VERIFIED, STATE_VERIFYING, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TC_ARRAY, TC_BOOLEAN, TC_BYTE, TC_CHAR, TC_CLASS, TC_CLASSEND, TC_DOUBLE, TC_FLOAT, TC_INT, TC_LONG, TC_PARAM, TC_PARAMEND, TC_SHORT, TC_VOID, TYPE_OF_OPERANDS, UNDEFINED, UNPREDICTABLE
 
Constructor Summary
private Utf8(byte[] data, int hash)
          Private constructor.
 
Method Summary
private static int addToTable_helper(byte[] b, int hash, int[] chain, int index)
           
static boolean checkUtf8(byte[] bytes)
          Check whether the given sequence of bytes is valid (pseudo-)utf8.
 void debugWrite()
           
 void dump(java.io.DataOutput out)
           
static java.lang.String fromUtf8(byte[] utf8)
          Convert the given sequence of (pseudo-)utf8 formatted bytes into a String.
static Utf8 get(byte[] b)
           
static Utf8 get(byte[] b, int startIndex, int endIndex)
           
static Utf8 get(java.lang.String s)
           
 Utf8 getArrayElementDescriptor()
           
 Utf8 getAsArrayDescriptor()
           
 Utf8 getAsClassDescriptor()
           
 Utf8 getClassName()
           
static int getID(byte[] b)
           
static int getID(byte[] b, int startIndex, int endIndex)
           
 Utf8.MethodDescriptorIterator getParamDescriptors()
           
private static void growTable_helper()
           
 int hashCode()
          Get a value that represents this Object, as uniquely as possible within the confines of an int.
static int hashCode(byte[] data)
           
static int hashCode(byte[] data, int startIndex, int endIndex)
           
 boolean isDescriptor(byte desc)
           
 boolean isValidMethodDescriptor()
           
 boolean isValidTypeDescriptor()
           
private  boolean isValidTypeDescriptor(int i)
           
static int lengthUtf8(java.lang.String s)
          Returns the length of a string's utf8 encoded form.
private static boolean memcmp(byte[] b1, byte[] b2)
           
private static boolean memcmp(byte[] b1, byte[] b2, int startIndex, int endIndex)
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
static byte[] toUtf8(java.lang.String s)
          Convert the given String into a sequence of (pseudo-)utf8 formatted bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TRACE

public static boolean TRACE

STARTING_TABLE_SIZE

public static final int STARTING_TABLE_SIZE
See Also:
Constant Field Values

STARTING_HASH_SIZE

public static final int STARTING_HASH_SIZE
See Also:
Constant Field Values

STARTING_CHAIN_SIZE

public static final int STARTING_CHAIN_SIZE
See Also:
Constant Field Values

table

public static Utf8[] table

size

public static int size

chains

public static int[][] chains

BYTE_DESC

public static final Utf8 BYTE_DESC

CHAR_DESC

public static final Utf8 CHAR_DESC

DOUBLE_DESC

public static final Utf8 DOUBLE_DESC

FLOAT_DESC

public static final Utf8 FLOAT_DESC

INT_DESC

public static final Utf8 INT_DESC

LONG_DESC

public static final Utf8 LONG_DESC

SHORT_DESC

public static final Utf8 SHORT_DESC

BOOLEAN_DESC

public static final Utf8 BOOLEAN_DESC

VOID_DESC

public static final Utf8 VOID_DESC

NO_NEW

public static boolean NO_NEW

data

private byte[] data

hash

private int hash

USE_CACHE

public static final boolean USE_CACHE
See Also:
Constant Field Values

DEBUG

public static final boolean DEBUG
See Also:
Constant Field Values

cache

private java.lang.String cache

STRICTLY_CHECK_FORMAT

static final boolean STRICTLY_CHECK_FORMAT
Strictly check the format of the utf8/pseudo-utf8 byte array in fromUtf8.

See Also:
Constant Field Values

ALLOW_NORMAL_UTF8

static final boolean ALLOW_NORMAL_UTF8
Set fromUtf8 to not throw an exception when given a normal utf8 byte array.

See Also:
Constant Field Values

ALLOW_PSEUDO_UTF8

static final boolean ALLOW_PSEUDO_UTF8
Set fromUtf8 to not throw an exception when given a pseudo utf8 byte array.

See Also:
Constant Field Values

WRITE_PSEUDO_UTF8

static final boolean WRITE_PSEUDO_UTF8
Set toUtf8 to write in pseudo-utf8 (rather than normal utf8).

See Also:
Constant Field Values
Constructor Detail

Utf8

private Utf8(byte[] data,
             int hash)
Private constructor. Use the get() method to create a Utf8 object.

Method Detail

get

public static Utf8 get(java.lang.String s)

get

public static Utf8 get(byte[] b)

get

public static Utf8 get(byte[] b,
                       int startIndex,
                       int endIndex)

getID

public static int getID(byte[] b)

getID

public static int getID(byte[] b,
                        int startIndex,
                        int endIndex)

isValidMethodDescriptor

public boolean isValidMethodDescriptor()

isValidTypeDescriptor

public boolean isValidTypeDescriptor()

isValidTypeDescriptor

private boolean isValidTypeDescriptor(int i)

isDescriptor

public boolean isDescriptor(byte desc)

getArrayElementDescriptor

public Utf8 getArrayElementDescriptor()

getClassName

public Utf8 getClassName()

getAsArrayDescriptor

public Utf8 getAsArrayDescriptor()

getAsClassDescriptor

public Utf8 getAsClassDescriptor()

getParamDescriptors

public Utf8.MethodDescriptorIterator getParamDescriptors()

memcmp

private static boolean memcmp(byte[] b1,
                              byte[] b2)

memcmp

private static boolean memcmp(byte[] b1,
                              byte[] b2,
                              int startIndex,
                              int endIndex)

addToTable_helper

private static int addToTable_helper(byte[] b,
                                     int hash,
                                     int[] chain,
                                     int index)

growTable_helper

private static void growTable_helper()

hashCode

public static int hashCode(byte[] data)

hashCode

public static int hashCode(byte[] data,
                           int startIndex,
                           int endIndex)

hashCode

public int hashCode()
Description copied from class: java.lang.Object
Get a value that represents this Object, as uniquely as possible within the confines of an int.

There are some requirements on this method which subclasses must follow:

  • Semantic equality implies identical hashcodes. In other words, if a.equals(b) is true, then a.hashCode() == b.hashCode() must be as well. However, the reverse is not necessarily true, and two objects may have the same hashcode without being equal.
  • It must be consistent. Whichever value o.hashCode() returns on the first invocation must be the value returned on all later invocations as long as the object exists. Notice, however, that the result of hashCode may change between separate executions of a Virtual Machine, because it is not invoked on the same object.

Notice that since hashCode is used in java.util.Hashtable and other hashing classes, a poor implementation will degrade the performance of hashing (so don't blindly implement it as returning a constant!). Also, if calculating the hash is time-consuming, a class may consider caching the results.

The default implementation returns System.identityHashCode(this)


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


dump

public void dump(java.io.DataOutput out)
          throws java.io.IOException

debugWrite

public void debugWrite()

fromUtf8

public static java.lang.String fromUtf8(byte[] utf8)
                                 throws UTFDataFormatError
Convert the given sequence of (pseudo-)utf8 formatted bytes into a String. The acceptable input formats are controlled by the STRICTLY_CHECK_FORMAT, ALLOW_NORMAL_UTF8, and ALLOW_PSEUDO_UTF8 flags.


toUtf8

public static byte[] toUtf8(java.lang.String s)
Convert the given String into a sequence of (pseudo-)utf8 formatted bytes. The output format is controlled by the WRITE_PSEUDO_UTF8 flag.


lengthUtf8

public static int lengthUtf8(java.lang.String s)
Returns the length of a string's utf8 encoded form.


checkUtf8

public static boolean checkUtf8(byte[] bytes)
Check whether the given sequence of bytes is valid (pseudo-)utf8.