1 16 17 package org.cojen.classfile.attribute; 18 19 import java.io.DataInput ; 20 import java.io.DataOutput ; 21 import java.io.IOException ; 22 import org.cojen.classfile.Attribute; 23 import org.cojen.classfile.ConstantPool; 24 import org.cojen.classfile.constant.ConstantUTFInfo; 25 26 33 public class SourceFileAttr extends Attribute { 34 35 private final ConstantUTFInfo mSourcefile; 36 37 public SourceFileAttr(ConstantPool cp, String fileName) { 38 this(cp, SOURCE_FILE, fileName); 39 } 40 41 public SourceFileAttr(ConstantPool cp, String name, String fileName) { 42 super(cp, name); 43 mSourcefile = cp.addConstantUTF(fileName); 44 } 45 46 public SourceFileAttr(ConstantPool cp, String name, int length, DataInput din) 47 throws IOException 48 { 49 super(cp, name); 50 int index = din.readUnsignedShort(); 51 if ((length -= 2) > 0) { 52 din.skipBytes(length); 53 } 54 mSourcefile = (ConstantUTFInfo)cp.getConstant(index); 55 } 56 57 60 public ConstantUTFInfo getFileName() { 61 return mSourcefile; 62 } 63 64 67 public int getLength() { 68 return 2; 69 } 70 71 public void writeDataTo(DataOutput dout) throws IOException { 72 dout.writeShort(mSourcefile.getIndex()); 73 } 74 } 75 | Popular Tags |