KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > alt > jiapi > file > SourceFileAttribute


1 package alt.jiapi.file;
2
3 import java.io.ByteArrayOutputStream JavaDoc;
4 import java.io.DataInputStream JavaDoc;
5 import java.io.DataOutputStream JavaDoc;
6 import java.io.IOException JavaDoc;
7 import java.util.List JavaDoc;
8 import java.util.LinkedList JavaDoc;
9 import java.util.Iterator JavaDoc;
10
11 /**
12  * Class CodeAttribute.
13  *
14  * @author Mika Riekkinen
15  * @see Java Virtual Machine Specification 2nd edition, ch. 4.7.7
16  */

17 public class SourceFileAttribute extends Attribute {
18     private short[] bytes;
19
20     SourceFileAttribute(short nameIndex, DataInputStream JavaDoc dis) throws IOException JavaDoc {
21         super(nameIndex);
22         this.bytes = new short[1];
23         bytes[0] = dis.readShort();
24     }
25     
26     public short getSourceFileIndex() {
27         return bytes[0];
28     }
29
30     public byte[] getBytes() {
31         ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
32         DataOutputStream JavaDoc dos = new DataOutputStream JavaDoc(baos);
33
34         try {
35             dos.writeShort(bytes[0]);
36         }
37         catch(IOException JavaDoc ioe) {
38             // Should not ever happen
39
throw new RuntimeException JavaDoc(ioe);
40         }
41
42         return baos.toByteArray();
43     }
44 }
45
46
Popular Tags