1 package alt.jiapi.file; 2 3 import java.io.ByteArrayOutputStream ; 4 import java.io.DataInputStream ; 5 import java.io.DataOutputStream ; 6 import java.io.IOException ; 7 import java.util.List ; 8 import java.util.LinkedList ; 9 import java.util.Iterator ; 10 11 17 public class LineNumberTableAttribute extends Attribute { 18 private List lineNumbers = new LinkedList (); 19 20 23 public static final String ATTRIBUTE_NAME = "LineNumberTable"; 24 25 LineNumberTableAttribute(short nameIndex, DataInputStream dis) throws IOException { 26 super(nameIndex); 27 28 short length = dis.readShort(); 29 for(int i = 0; i < length; i++) { 30 short start_pc = dis.readShort(); 31 short line_number = dis.readShort(); 32 33 lineNumbers.add(new Entry(start_pc, line_number)); 34 } 35 } 36 37 38 public List getEntries() { 39 return lineNumbers; 40 } 41 42 43 public byte[] getBytes() { 44 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 45 DataOutputStream dos = new DataOutputStream (baos); 46 47 try { 48 dos.writeShort(lineNumbers.size()); 49 50 Iterator i = lineNumbers.iterator(); 51 while(i.hasNext()) { 52 Entry lnte = (Entry)i.next(); 53 dos.writeShort(lnte.getStartPc()); 54 dos.writeShort(lnte.getLineNumber()); 55 } 56 } 57 catch(IOException ioe) { 58 throw new RuntimeException (ioe); 60 } 61 62 return baos.toByteArray(); 63 } 64 65 66 public class Entry { 67 private short start_pc; 68 private short line_number; 69 70 public Entry(short start_pc, short line_number) { 71 this.start_pc = start_pc; 72 this.line_number = line_number; 73 } 74 75 78 public short getStartPc() { 79 return start_pc; 80 } 81 82 85 public void setStartPc(short start_pc) { 86 this.start_pc = start_pc; 87 } 88 89 public short getLineNumber() { 90 return line_number; 91 } 92 } 93 } 94 95 | Popular Tags |