54 * 55 * @param file Input stream 56 * @throws IOException 57 */ 58 ConstantPackage(final DataInput file) throws IOException { 59 this(file.readUnsignedShort()); 60 } 61 62 63 /** 64 * @param name_index Name index in constant pool. Should refer to a 65 * ConstantUtf8. 66 */ 67 public ConstantPackage(final int name_index) { 68 super(Const.CONSTANT_Package); 69 this.name_index = name_index; 70 } 71 72 73 /** 74 * Called by objects that are traversing the nodes of the tree implicitely 75 * defined by the contents of a Java class. I.e., the hierarchy of methods, 76 * fields, attributes, etc. spawns a tree of objects. 77 * 78 * @param v Visitor object 79 */ 80 @Override 81 public void accept( final Visitor v ) { 82 v.visitConstantPackage(this); 83 } 84 85 86 /** 87 * Dump constant package to file stream in binary format. 88 * 89 * @param file Output file stream 90 * @throws IOException 91 */ 92 @Override 93 public final void dump( final DataOutputStream file ) throws IOException { 94 file.writeByte(super.getTag()); 95 file.writeShort(name_index); 96 } 97 98 99 /** 100 * @return Name index in constant pool of package name. 101 */ 102 public final int getNameIndex() { 103 return name_index; 104 } 105 106 107 /** 108 * @param name_index the name index in the constant pool of this Constant Package 109 */ 110 public final void setNameIndex( final int name_index ) { 111 this.name_index = name_index; 112 } 113 114 115 /** @return String object 116 */ 117 @Override 118 public Object getConstantValue( final ConstantPool cp ) { 119 final Constant c = cp.getConstant(name_index, Const.CONSTANT_Utf8); 120 return ((ConstantUtf8) c).getBytes(); 121 } 122 123 124 /** @return dereferenced string 125 */ 126 public String getBytes( final ConstantPool cp ) { 127 return (String) getConstantValue(cp); 128 } 129 130 131 /** 132 * @return String representation. 133 */ 134 @Override 135 public final String toString() { 136 return super.toString() + "(name_index = " + name_index + ")"; 137 } 138 } | 54 * 55 * @param file Input stream 56 * @throws IOException 57 */ 58 ConstantPackage(final DataInput file) throws IOException { 59 this(file.readUnsignedShort()); 60 } 61 62 63 /** 64 * @param name_index Name index in constant pool. Should refer to a 65 * ConstantUtf8. 66 */ 67 public ConstantPackage(final int name_index) { 68 super(Const.CONSTANT_Package); 69 this.name_index = name_index; 70 } 71 72 73 /** 74 * Called by objects that are traversing the nodes of the tree implicitly 75 * defined by the contents of a Java class. I.e., the hierarchy of methods, 76 * fields, attributes, etc. spawns a tree of objects. 77 * 78 * @param v Visitor object 79 */ 80 @Override 81 public void accept( final Visitor v ) { 82 v.visitConstantPackage(this); 83 } 84 85 86 /** 87 * Dump constant package to file stream in binary format. 88 * 89 * @param file Output file stream 90 * @throws IOException 91 */ 92 @Override 93 public void dump( final DataOutputStream file ) throws IOException { 94 file.writeByte(super.getTag()); 95 file.writeShort(name_index); 96 } 97 98 99 /** 100 * @return Name index in constant pool of package name. 101 */ 102 public int getNameIndex() { 103 return name_index; 104 } 105 106 107 /** 108 * @param name_index the name index in the constant pool of this Constant Package 109 */ 110 public void setNameIndex( final int name_index ) { 111 this.name_index = name_index; 112 } 113 114 115 /** @return String object 116 */ 117 @Override 118 public Object getConstantValue( final ConstantPool cp ) { 119 final Constant c = cp.getConstant(name_index, Const.CONSTANT_Utf8); 120 return ((ConstantUtf8) c).getBytes(); 121 } 122 123 124 /** @return dereferenced string 125 */ 126 public String getBytes( final ConstantPool cp ) { 127 return (String) getConstantValue(cp); 128 } 129 130 131 /** 132 * @return String representation. 133 */ 134 @Override 135 public String toString() { 136 return super.toString() + "(name_index = " + name_index + ")"; 137 } 138 } |