KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jas > GenericAttr


1 /**
2  * This is an opaque attribute that lets you add an uninterpreted
3  * stream of bytes into an attribute in a class file. This can be
4  * used (for instance) to embed versioning or signatures into the
5  * class file or method.
6  *
7  * @author $Author: fqian $
8  * @version $Revision: 1.1 $
9  */

10 package jas;
11
12 import java.io.*;
13
14 public class GenericAttr
15 {
16   CP attr_name;
17   byte data[];
18
19   /**
20    * Make up a new attribute
21    * @param name Name to be associated with the attribute
22    * @data stream of bytes to be placed with the attribute
23    * @see ClassEnv#addGenericAttr
24    * @see CodeAttr#addGenericAttr
25    */

26   public GenericAttr(String JavaDoc name, byte data[])
27   {
28     attr_name = new AsciiCP(name);
29     this.data = data;
30   }
31   /**
32    * Make up a new attribute
33    * @param name CP to be defined as the name of the attribute
34    * @data stream of bytes to be placed with the attribute
35    * @see ClassEnv#addGenericAttr
36    * @see CodeAttr#addGenericAttr
37    */

38   public GenericAttr(CP name, byte data[])
39   {
40     attr_name = name;
41     this.data = data;
42   }
43
44   void resolve(ClassEnv e)
45   { e.addCPItem(attr_name); }
46
47   int size()
48   { return (2 + 4 + data.length); }
49
50   void write(ClassEnv e, DataOutputStream out)
51     throws IOException, jasError
52   {
53     out.writeShort(e.getCPIndex(attr_name));
54     out.writeInt(data.length);
55     out.write(data);
56   }
57 }
58
59
Popular Tags