001 /*
002 * Copyright 2002 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026
027
028 package sun.tools.javap;
029
030 import java.io.*;
031
032 /**
033 * Reads and stores attribute information.
034 *
035 * @author Sucheta Dambalkar (Adopted code from jdis)
036 */
037 class AttrData {
038 ClassData cls;
039 int name_cpx;
040 int datalen;
041 byte data[];
042
043 public AttrData (ClassData cls) {
044 this.cls=cls;
045 }
046
047 /**
048 * Reads unknown attribute.
049 */
050 public void read(int name_cpx, DataInputStream in) throws IOException {
051 this.name_cpx=name_cpx;
052 datalen=in.readInt();
053 data=new byte[datalen];
054 in.readFully(data);
055 }
056
057 /**
058 * Reads just the name of known attribute.
059 */
060 public void read(int name_cpx){
061 this.name_cpx=name_cpx;
062 }
063
064 /**
065 * Returns attribute name.
066 */
067 public String getAttrName(){
068 return cls.getString(name_cpx);
069 }
070
071 /**
072 * Returns attribute data.
073 */
074 public byte[] getData(){
075 return data;
076 }
077 }