1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.classfile; 23 24 25 26 import com.sun.org.apache.bcel.internal.Constants; 27 import java.io.*; 28 29 /** 30 * This class is derived from the abstract 31 * <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class 32 * and represents a reference to an int object. 33 * 34 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 35 * @see Constant 36 */ 37 public final class ConstantInteger extends Constant implements ConstantObject { 38 private int bytes; 39 40 /** 41 * @param bytes Data 42 */ 43 public ConstantInteger(int bytes) 44 { 45 super(Constants.CONSTANT_Integer); 46 this.bytes = bytes; 47 } 48 49 /** 50 * Initialize from another object. 51 */ 52 public ConstantInteger(ConstantInteger c) { 53 this(c.getBytes()); 54 } 55 56 /** 57 * Initialize instance from file data. 58 * 59 * @param file Input stream 60 * @throws IOException 61 */ 62 ConstantInteger(DataInputStream file) throws IOException 63 { 64 this(file.readInt()); 65 } 66 67 /** 68 * Called by objects that are traversing the nodes of the tree implicitely 69 * defined by the contents of a Java class. I.e., the hierarchy of methods, 70 * fields, attributes, etc. spawns a tree of objects. 71 * 72 * @param v Visitor object 73 */ 74 public void accept(Visitor v) { 75 v.visitConstantInteger(this); 76 } 77 78 /** 79 * Dump constant integer to file stream in binary format. 80 * 81 * @param file Output file stream 82 * @throws IOException 83 */ 84 public final void dump(DataOutputStream file) throws IOException 85 { 86 file.writeByte(tag); 87 file.writeInt(bytes); 88 } 89 90 /** 91 * @return data, i.e., 4 bytes. 92 */ 93 public final int getBytes() { return bytes; } 94 95 /** 96 * @param bytes. 97 */ 98 public final void setBytes(int bytes) { 99 this.bytes = bytes; 100 } 101 102 /** 103 * @return String representation. 104 */ 105 public final String toString() { 106 return super.toString() + "(bytes = " + bytes + ")"; 107 } 108 109 /** @return Integer object 110 */ 111 public Object getConstantValue(ConstantPool cp) { 112 return new Integer(bytes); 113 } 114 }