1 26 27 package net.sourceforge.groboutils.codecoverage.v2.logger; 28 29 import java.io.BufferedReader ; 30 import java.io.File ; 31 import java.io.FileReader ; 32 import java.io.IOException ; 33 34 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogRecord; 35 import net.sourceforge.groboutils.codecoverage.v2.IClassChannelLogReader; 36 import net.sourceforge.groboutils.codecoverage.v2.util.HexUtil; 37 38 48 public class DirectoryClassChannelLogReader implements IClassChannelLogReader 49 { 50 private File classLogFile; 51 private String classSig; 52 private BufferedReader in; 53 54 55 DirectoryClassChannelLogReader( File log, String classSig ) 56 { 57 if (log == null || classSig == null) 58 { 59 throw new IllegalArgumentException ( "No null args." ); 60 } 61 if (!log.exists() || !log.isFile()) 62 { 63 throw new IllegalArgumentException ( "File "+log+ 64 " is not a file or doesn't exist." ); 65 } 66 this.classLogFile = log; 67 this.classSig = classSig; 68 } 69 70 71 80 public synchronized IChannelLogRecord nextRecord() 81 throws IOException 82 { 83 if (this.classLogFile == null) 84 { 85 return null; 86 } 87 if (this.in == null) 88 { 89 this.in = new BufferedReader ( 90 new FileReader ( this.classLogFile ) ); 91 } 92 93 String s = this.in.readLine(); 94 if (s == null) 95 { 96 close(); 97 return null; 98 } 99 100 HexUtil.TwoShorts ts = new HexUtil.TwoShorts(); 102 if (!HexUtil.getInstance().parseTwoHex( s.trim(), ts, ' ', 0)) 103 { 104 close(); 105 throw new IOException ( "Invalid file format in '"+ 106 this.classLogFile+"'." ); 107 } 108 109 return new DefaultChannelLogRecord( 110 this.classSig, ts.a, ts.b ); 111 112 } 113 114 115 public void close() 116 throws IOException 117 { 118 if (this.in != null) 119 { 120 this.in.close(); 121 this.in = null; 122 } 123 this.classLogFile = null; 124 } 125 126 127 protected void finalize() throws Throwable 128 { 129 close(); 130 super.finalize(); 131 } 132 } 133 134 | Popular Tags |