1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 6 package com.sun.org.apache.bcel.internal.classfile; 7 8 /* ==================================================================== 9 * The Apache Software License, Version 1.1 10 * 11 * Copyright (c) 2001 The Apache Software Foundation. All rights 12 * reserved. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions 16 * are met: 17 * 18 * 1. Redistributions of source code must retain the above copyright 19 * notice, this list of conditions and the following disclaimer. 20 * 21 * 2. Redistributions in binary form must reproduce the above copyright 22 * notice, this list of conditions and the following disclaimer in 23 * the documentation and/or other materials provided with the 24 * distribution. 25 * 26 * 3. The end-user documentation included with the redistribution, 27 * if any, must include the following acknowledgment: 28 * "This product includes software developed by the 29 * Apache Software Foundation (http://www.apache.org/)." 30 * Alternately, this acknowledgment may appear in the software itself, 31 * if and wherever such third-party acknowledgments normally appear. 32 * 33 * 4. The names "Apache" and "Apache Software Foundation" and 34 * "Apache BCEL" must not be used to endorse or promote products 35 * derived from this software without prior written permission. For 36 * written permission, please contact apache@apache.org. 37 * 38 * 5. Products derived from this software may not be called "Apache", 39 * "Apache BCEL", nor may "Apache" appear in their name, without 40 * prior written permission of the Apache Software Foundation. 41 * 42 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 43 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 44 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 45 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 46 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 47 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 48 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 49 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 50 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 51 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 52 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 53 * SUCH DAMAGE. 54 * ==================================================================== 55 * 56 * This software consists of voluntary contributions made by many 57 * individuals on behalf of the Apache Software Foundation. For more 58 * information on the Apache Software Foundation, please see 59 * <http://www.apache.org/>. 60 */ 61 62 63 import com.sun.org.apache.bcel.internal.Constants; 64 import java.io.*; 65 66 /** 67 * This class is derived from the abstract 68 * <A HREF="com.sun.org.apache.bcel.internal.classfile.Constant.html">Constant</A> class 69 * and represents a reference to an int object. 70 * 71 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 72 * @see Constant 73 */ 74 public final class ConstantInteger extends Constant implements ConstantObject { 75 private int bytes; 76 77 /** 78 * @param bytes Data 79 */ 80 public ConstantInteger(int bytes) 81 { 82 super(Constants.CONSTANT_Integer); 83 this.bytes = bytes; 84 } 85 86 /** 87 * Initialize from another object. 88 */ 89 public ConstantInteger(ConstantInteger c) { 90 this(c.getBytes()); 91 } 92 93 /** 94 * Initialize instance from file data. 95 * 96 * @param file Input stream 97 * @throws IOException 98 */ 99 ConstantInteger(DataInputStream file) throws IOException 100 { 101 this(file.readInt()); 102 } 103 104 /** 105 * Called by objects that are traversing the nodes of the tree implicitely 106 * defined by the contents of a Java class. I.e., the hierarchy of methods, 107 * fields, attributes, etc. spawns a tree of objects. 108 * 109 * @param v Visitor object 110 */ 111 public void accept(Visitor v) { 112 v.visitConstantInteger(this); 113 } 114 115 /** 116 * Dump constant integer to file stream in binary format. 117 * 118 * @param file Output file stream 119 * @throws IOException 120 */ 121 public final void dump(DataOutputStream file) throws IOException 122 { 123 file.writeByte(tag); 124 file.writeInt(bytes); 125 } 126 127 /** 128 * @return data, i.e., 4 bytes. 129 */ 130 public final int getBytes() { return bytes; } 131 132 /** 133 * @param bytes. 134 */ 135 public final void setBytes(int bytes) { 136 this.bytes = bytes; 137 } 138 139 /** 140 * @return String representation. 141 */ 142 public final String toString() { 143 return super.toString() + "(bytes = " + bytes + ")"; 144 } 145 146 /** @return Integer object 147 */ 148 public Object getConstantValue(ConstantPool cp) { 149 return new Integer(bytes); 150 } 151 }