KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jdo > api > persistence > enhancer > classfile > GenericAttribute


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24
25 package com.sun.jdo.api.persistence.enhancer.classfile;
26
27 import java.io.*;
28
29 /**
30  * GenericAttribute represents a class attribute in a class file which
31  * is not recognized as any supported attribute type. These attributes
32  * are maintained, and are not modified in any way.
33  */

34
35 public class GenericAttribute extends ClassAttribute {
36
37   /* The bytes of the attribute following the name */
38   byte attributeBytes[];
39
40   /* public accessors */
41
42   /**
43    * constructor
44    */

45   public GenericAttribute(ConstUtf8 attrName, byte attrBytes[]) {
46     super(attrName);
47     attributeBytes = attrBytes;
48   }
49
50   void write(DataOutputStream out) throws IOException {
51     out.writeShort(attrName().getIndex());
52     out.writeInt(attributeBytes.length);
53     out.write(attributeBytes, 0, attributeBytes.length);
54   }
55
56   void print(PrintStream out, int indent) {
57     ClassPrint.spaces(out, indent);
58     out.println("Generic Attribute(" + attrName().asString() + "): " +//NOI18N
59
Integer.toString(attributeBytes.length) +
60                 " in length");//NOI18N
61
for (int i=0; i<attributeBytes.length; i++) {
62       if ((i % 16) == 0) {
63     if (i != 0)
64       out.println();
65     out.print(i + " :");//NOI18N
66
}
67       out.print(" " + Integer.toString((attributeBytes[i] & 0xff), 16));//NOI18N
68
}
69     out.println();
70   }
71 }
72
73
Popular Tags