1 26 27 package net.sourceforge.groboutils.codecoverage.v2.logger; 28 29 import java.io.File ; 30 import java.io.FileWriter ; 31 import java.io.IOException ; 32 33 import net.sourceforge.groboutils.codecoverage.v2.IChannelLogger; 34 35 36 52 public class DirectoryChannelLogger implements IChannelLogger 53 { 54 public static final String CLASS_LOG_EXTENTION = ".class.log"; 55 56 protected File baseDir; 57 58 59 public DirectoryChannelLogger( File baseDir ) 60 { 61 this.baseDir = baseDir; 63 if (baseDir == null) 64 { 65 System.err.println("DirectoryLogger base directory is null."); 66 } 67 else 68 { 69 if (!baseDir.exists()) 70 { 71 baseDir.mkdir(); 72 } 73 } 74 } 75 76 77 89 public void cover( String classSignature, short methodIndex, 90 short markIndex ) 91 { 92 if (this.baseDir != null) 93 { 94 File f = getClassFile( this.baseDir, classSignature ); 96 FileWriter fw = null; 97 try 98 { 99 char[] out = createCoverString( methodIndex, markIndex ); 100 synchronized (this) 101 { 102 fw = new FileWriter ( f.toString(), true ); 103 fw.write( out ); 104 fw.flush(); 105 } 107 } 108 catch (IOException ioe) 109 { 110 ioe.printStackTrace(); 112 113 this.baseDir = null; 115 } 116 finally 117 { 118 if (fw != null) 119 { 120 try 121 { 122 fw.close(); 123 } 124 catch (IOException ioe) 125 { 126 ioe.printStackTrace(); 128 129 } 131 } 132 } 133 } 134 } 135 136 137 private static final char[] HEX = { 138 '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' 139 }; 140 146 protected static final char[] createCoverString( 147 short methodIndex, short markIndex ) 148 { 149 char c[] = new char[10]; 150 c[9] = '\n'; 151 152 int imeth = (int)methodIndex; 155 int imark = (int)markIndex; 156 157 159 c[8] = HEX[ imark & 0xf ]; imark >>>= 4; 161 c[7] = HEX[ imark & 0xf ]; imark >>>= 4; 162 c[6] = HEX[ imark & 0xf ]; imark >>>= 4; 163 c[5] = HEX[ imark & 0xf ]; 164 165 c[4] = ' '; 166 167 c[3] = HEX[ imeth & 0xf ]; imeth >>>= 4; 168 c[2] = HEX[ imeth & 0xf ]; imeth >>>= 4; 169 c[1] = HEX[ imeth & 0xf ]; imeth >>>= 4; 170 c[0] = HEX[ imeth & 0xf ]; 171 172 return c; 173 } 174 175 176 179 protected static final File getClassFile( File basedir, 180 String classSignature ) 181 { 182 return new File ( basedir, classSignature + CLASS_LOG_EXTENTION ); 183 } 184 } 185 186 | Popular Tags |