1 /*
2 * @(#)AttributeInfo.java 1.4 95/08/16 Chuck McManis
3 *
4 * Copyright (c) 1996 Chuck McManis, All Rights Reserved.
5 *
6 * Permission to use, copy, modify, and distribute this software
7 * and its documentation for NON-COMMERCIAL purposes and without
8 * fee is hereby granted provided that this copyright notice
9 * appears in all copies.
10 *
11 * CHUCK MCMANIS MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
12 * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
13 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. CHUCK MCMANIS SHALL NOT BE
15 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
16 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
17 */
18
19 package ch.elca.dependency.core.classinfo;
20
21 import java.io.DataInputStream;
22 import java.io.DataOutputStream;
23 import java.io.IOException;
24
25 /***
26 * This class defines the generic Attribute type for Java class files.
27 * It is a little bit smart in that for some Attributes it can display
28 * them intelligently if it also has access to the constant pool of the
29 * current class.
30 *
31 * @version 1.4, 16 Aug 1995
32 * @author Chuck McManis
33 * @see ch.elca.dependency.rawmodel.classinfo.Reader
34 */
35 public class AttributeInfo {
36
37 ConstantPoolInfo name; // attribute name
38 byte data[]; // attribute's contents
39
40 public AttributeInfo(ConstantPoolInfo newName, byte newData[]) {
41 name = name;
42 data = newData;
43 }
44
45 public AttributeInfo() {
46 }
47
48 public boolean read(DataInputStream di, ConstantPoolInfo pool[])
49 throws IOException {
50 int len;
51
52 name = pool[di.readShort()];
53 len = di.readInt();
54 data = new byte[len];
55 len = di.read(data);
56 if ( len != data.length ) {
57 return (false);
58 }
59 return (true);
60 }
61
62 public void write(DataOutputStream dos, ConstantPoolInfo pool[])
63 throws IOException, Exception {
64 dos.writeShort(ConstantPoolInfo.indexOf(name, pool));
65 dos.writeInt(data.length);
66 dos.write(data, 0, data.length);
67 }
68
69 short indexFromBytes(byte a[]) {
70 return (short)(((a[0] << 8) & (0xff << 8)) |
71 ((a[1] << 0) & (0xff << 0)));
72 }
73
74 public String toString(ConstantPoolInfo pool[]) {
75 StringBuffer x = new StringBuffer();
76 String type = name.toString();
77 ConstantPoolInfo item;
78
79 if ( type.compareTo("ConstantValue") == 0 ) {
80 item = pool[indexFromBytes(data)];
81 return (item.toString());
82 } else if ( type.compareTo("SourceFile") == 0 ) {
83 item = pool[indexFromBytes(data)];
84 return (item.toString());
85 } else {
86 x.append(type+"<"+data.length+" bytes>");
87 }
88 return (x.toString());
89 }
90
91 public String toBoolean(ConstantPoolInfo pool[]) {
92 ConstantPoolInfo item = pool[indexFromBytes(data)];
93
94 if ( item.intValue == 0 )
95 return ("= false");
96 return ("= true");
97 }
98
99 public String toString() {
100 return (name.toString()+" <"+data.length+" bytes>");
101 }
102 }
This page was automatically generated by Maven