/** * Switches to a byte array representation of the UTF-8 data. */ private void switchToByteArrayRepresentation() throws UnsupportedEncodingException { if (bytes == null) { bytes = getByteArrayRepresentation(string); string = null; } }
/** * Returns the string of the Utf8Constant at the specified index in the * reusable constant pool. */ private String getString(int constantIndex) { return ((Utf8Constant)constantPool[constantIndex]).getString(); }
/** * Switches to a String representation of the UTF-8 data. */ private void switchToStringRepresentation() throws UnsupportedEncodingException { if (string == null) { string = getStringRepresentation(bytes); bytes = null; } }
/** * Finds or creates a Utf8Constant constant pool entry for the given string. * @return the constant pool index of the Utf8Constant. */ public int addUtf8Constant(String string) { int constantPoolCount = targetClass.u2constantPoolCount; Constant[] constantPool = targetClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_Utf8) { Utf8Constant utf8Constant = (Utf8Constant)constant; if (utf8Constant.getString().equals(string)) { return index; } } } return addConstant(new Utf8Constant(string)); }
((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { int u2length = dataInput.readUnsignedShort(); // Read the UTF-8 bytes. byte[] bytes = new byte[u2length]; dataInput.readFully(bytes); utf8Constant.setBytes(bytes); }
private Constant createConstant() { int u1tag = dataInput.readUnsignedByte(); switch (u1tag) { case ClassConstants.CONSTANT_Utf8: return new Utf8Constant(); case ClassConstants.CONSTANT_Integer: return new IntegerConstant(); case ClassConstants.CONSTANT_Float: return new FloatConstant(); case ClassConstants.CONSTANT_Long: return new LongConstant(); case ClassConstants.CONSTANT_Double: return new DoubleConstant(); case ClassConstants.CONSTANT_String: return new StringConstant(); case ClassConstants.CONSTANT_Fieldref: return new FieldrefConstant(); case ClassConstants.CONSTANT_Methodref: return new MethodrefConstant(); case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant(); case ClassConstants.CONSTANT_Class: return new ClassConstant(); case ClassConstants.CONSTANT_NameAndType: return new NameAndTypeConstant(); default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool"); } }
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { byte[] bytes = utf8Constant.getBytes(); dataOutput.writeShort(bytes.length); dataOutput.write(bytes); }
/** * Returns the UTF-8 data as a String. */ public String getString() { try { switchToStringRepresentation(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage()); } return string; }
/** * Returns the UTF-8 data as an array of bytes. */ public byte[] getBytes() { try { switchToByteArrayRepresentation(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage()); } return bytes; }
/** * Finds or creates a Utf8Constant constant pool entry for the given string. * @return the constant pool index of the Utf8Constant. */ public int addUtf8Constant(String string) { int constantPoolCount = targetClass.u2constantPoolCount; Constant[] constantPool = targetClass.constantPool; // Check if the entry already exists. for (int index = 1; index < constantPoolCount; index++) { Constant constant = constantPool[index]; if (constant != null && constant.getTag() == ClassConstants.CONSTANT_Utf8) { Utf8Constant utf8Constant = (Utf8Constant)constant; if (utf8Constant.getString().equals(string)) { return index; } } } return addConstant(new Utf8Constant(string)); }
((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { int u2length = dataInput.readUnsignedShort(); // Read the UTF-8 bytes. byte[] bytes = new byte[u2length]; dataInput.readFully(bytes); utf8Constant.setBytes(bytes); }
private Constant createConstant() { int u1tag = dataInput.readUnsignedByte(); switch (u1tag) { case ClassConstants.CONSTANT_Utf8: return new Utf8Constant(); case ClassConstants.CONSTANT_Integer: return new IntegerConstant(); case ClassConstants.CONSTANT_Float: return new FloatConstant(); case ClassConstants.CONSTANT_Long: return new LongConstant(); case ClassConstants.CONSTANT_Double: return new DoubleConstant(); case ClassConstants.CONSTANT_String: return new StringConstant(); case ClassConstants.CONSTANT_Fieldref: return new FieldrefConstant(); case ClassConstants.CONSTANT_Methodref: return new MethodrefConstant(); case ClassConstants.CONSTANT_InterfaceMethodref: return new InterfaceMethodrefConstant(); case ClassConstants.CONSTANT_Class: return new ClassConstant(); case ClassConstants.CONSTANT_NameAndType: return new NameAndTypeConstant(); default: throw new RuntimeException("Unknown constant type ["+u1tag+"] in constant pool"); } }
public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant) { byte[] bytes = utf8Constant.getBytes(); dataOutput.writeUnsignedShort(bytes.length); dataOutput.write(bytes); }
/** * Returns the UTF-8 data as a String. */ public String getString() { try { switchToStringRepresentation(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage()); } return string; }
/** * Returns the UTF-8 data as an array of bytes. */ public byte[] getBytes() { try { switchToByteArrayRepresentation(); } catch (UnsupportedEncodingException ex) { throw new RuntimeException(ex.getMessage()); } return bytes; }
/** * Returns the string of the Utf8Constant at the specified index in the * reusable constant pool. */ private String getString(int constantIndex) { return ((Utf8Constant)constantPool[constantIndex]).getString(); }