/** Get a string from the constant pool, optionally replacing '/' with '.'. */ private String getConstantPoolString(final int cpIdx, final boolean replaceSlashWithDot, final boolean stripLSemicolon) { final int constantPoolStringOffset = getConstantPoolStringOffset(cpIdx, /* subFieldIdx = */ 0); return constantPoolStringOffset == 0 ? null : readString(constantPoolStringOffset, replaceSlashWithDot, stripLSemicolon); }
/** * Get the first UTF8 byte of a string in the constant pool, or '\0' if the string is null or empty. */ private byte getConstantPoolStringFirstByte(final int cpIdx) { final int constantPoolStringOffset = getConstantPoolStringOffset(cpIdx, /* subFieldIdx = */ 0); if (constantPoolStringOffset == 0) { return '\0'; } final int utfLen = readUnsignedShort(constantPoolStringOffset); if (utfLen == 0) { return '\0'; } return buf[constantPoolStringOffset + 2]; }
/** * Get a string from the constant pool. * * @param cpIdx * the constant pool index * @param subFieldIdx * should be 0 for CONSTANT_Utf8, CONSTANT_Class and CONSTANT_String, and for * CONSTANT_NameAndType_info, fetches the name for value 0, or the type descriptor for value 1. */ private String getConstantPoolString(final int cpIdx, final int subFieldIdx) { final int constantPoolStringOffset = getConstantPoolStringOffset(cpIdx, subFieldIdx); return constantPoolStringOffset == 0 ? null : readString(constantPoolStringOffset, /* replaceSlashWithDot = */ false, /* stripLSemicolon = */ false); }
/** * Compare a string in the constant pool with a given constant, without constructing the String object. */ private boolean constantPoolStringEquals(final int cpIdx, final String otherString) { final int strOffset = getConstantPoolStringOffset(cpIdx, /* subFieldIdx = */ 0); if (strOffset == 0) { return otherString == null; } final int strLen = readUnsignedShort(strOffset); final int otherLen = otherString.length(); if (strLen != otherLen) { return false; } final int strStart = strOffset + 2; for (int i = 0; i < strLen; i++) { if ((char) (buf[strStart + i] & 0xff) != otherString.charAt(i)) { return false; } } return true; }