/** * @since 6.0 */ public static ConstantUtf8 getInstance(final String s) { return new ConstantUtf8(s); }
/** * @since 6.0 */ public static ConstantUtf8 getCachedInstance(final String s) { if (s.length() > MAX_CACHED_SIZE) { skipped++; return new ConstantUtf8(s); } considered++; synchronized (ConstantUtf8.class) { // might be better with a specific lock object ConstantUtf8 result = CACHE_HOLDER.CACHE.get(s); if (result != null) { hits++; return result; } result = new ConstantUtf8(s); CACHE_HOLDER.CACHE.put(s, result); return result; } }
/** * Add a new Utf8 constant to the ConstantPool, if it is not already in there. * * @param n Utf8 string to add * @return index of entry */ public int addUtf8( final String n ) { int ret; if ((ret = lookupUtf8(n)) != -1) { return ret; // Already in CP } adjustSize(); ret = index; constants[index++] = new ConstantUtf8(n); if (!utf8_table.containsKey(n)) { utf8_table.put(n, new Index(ret)); } return ret; }
/** * Add a new Utf8 constant to the ConstantPool, if it is not already in there. * * @param n Utf8 string to add * @return index of entry */ public int addUtf8(String n) { int ret; if((ret = lookupUtf8(n)) != -1) return ret; // Already in CP adjustSize(); ret = index; constants[index++] = new ConstantUtf8(n); utf8_table.put(n, new Index(ret)); return ret; }
/** * Read one constant from the given file, the type depends on a tag byte. * * @param file Input stream * @return Constant object */ static final Constant readConstant(DataInputStream file) throws IOException, ClassFormatException { byte b = file.readByte(); // Read tag byte switch(b) { case Constants.CONSTANT_Class: return new ConstantClass(file); case Constants.CONSTANT_Fieldref: return new ConstantFieldref(file); case Constants.CONSTANT_Methodref: return new ConstantMethodref(file); case Constants.CONSTANT_InterfaceMethodref: return new ConstantInterfaceMethodref(file); case Constants.CONSTANT_String: return new ConstantString(file); case Constants.CONSTANT_Integer: return new ConstantInteger(file); case Constants.CONSTANT_Float: return new ConstantFloat(file); case Constants.CONSTANT_Long: return new ConstantLong(file); case Constants.CONSTANT_Double: return new ConstantDouble(file); case Constants.CONSTANT_NameAndType: return new ConstantNameAndType(file); case Constants.CONSTANT_Utf8: return new ConstantUtf8(file); default: throw new ClassFormatException("Invalid byte tag in constant pool: " + b); } } }