1 26 27 package net.sourceforge.groboutils.codecoverage.v2.datastore; 28 29 import java.io.IOException ; 30 import java.io.Reader ; 31 import java.io.StringReader ; 32 import java.io.StringWriter ; 33 import java.io.Writer ; 34 35 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisMetaData; 36 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 37 38 45 class ClassRecordIO 46 { 47 public ClassRecordIO() 48 { 49 } 51 52 53 56 public void writeClass( ClassRecord cr, Writer out ) 57 throws IOException 58 { 59 StringBuffer sb = new StringBuffer (); 60 61 sb.append( cr.getClassName().length() ). 62 append( ':' ). 63 append( cr.getClassName() ). 64 append( ',' ). 65 append( cr.getClassCRC() ). 66 append( ',' ). 67 append( cr.getSourceFileName().length() ). 68 append( ':' ). 69 append( cr.getSourceFileName() ). 70 append( ',' ); 71 72 int count = cr.getMethodCount(); 73 sb.append( count ).append( '[' ); 74 for (short i = 0; i < count; ++i) 75 { 76 sb.append( '(' ); 77 String m = cr.getMethodAt( i ); 78 sb.append( m.length() ). 79 append( ':' ). 80 append( m ); 81 sb.append( ')' ); 82 } 83 sb.append( ']' ); 84 85 out.write( sb.toString() ); 86 } 87 88 89 92 public ClassRecord readClass( AnalysisModuleSet ams, Reader in ) 93 throws IOException 94 { 95 int count = ReadUtil.toInt( ReadUtil.readTo( in, ':' ) ); 96 String className = ReadUtil.readCount( in, count ); 97 ReadUtil.readTo( in, ',' ); 98 long classCRC = ReadUtil.toLong( ReadUtil.readTo( in, ',' ) ); 99 count = ReadUtil.toInt( ReadUtil.readTo( in, ':' ) ); 100 String sourceFileName = ReadUtil.readCount( in, count ); 101 ReadUtil.readTo( in, ',' ); 102 103 int methodCount = ReadUtil.toInt( ReadUtil.readTo( in, '[' ) ); 104 String [] methodSigs = new String [ methodCount ]; 105 for (int i = 0; i < methodCount; ++i) 106 { 107 ReadUtil.readTo( in, '(' ); 108 count = ReadUtil.toInt( ReadUtil.readTo( in, ':' ) ); 109 methodSigs[i] = ReadUtil.readCount( in, count ); 110 ReadUtil.readTo( in, ')' ); 111 } 112 ReadUtil.readTo( in, ']' ); 113 114 return new ClassRecord( className, classCRC, sourceFileName, 115 methodSigs, ams ); 116 } 117 118 119 121 122 125 public void writeMarksForAnalysisModule( ClassRecord cr, 126 IAnalysisModule am, Writer out ) 127 throws IOException 128 { 129 writeMarksForMeasure( cr, am.getMeasureName(), out ); 130 } 131 132 133 136 public void writeMarksForMeasure( ClassRecord cr, 137 String measureName, Writer out ) 138 throws IOException 139 { 140 MarkRecord mr[] = cr.getMarksForAnalysisModule( measureName ); 141 StringBuffer sb = new StringBuffer (); 142 sb.append( measureName.length() ). 143 append( ':' ). 144 append( measureName ). 145 append( ',' ). 146 append( mr.length ). 147 append( '[' ); 148 for (int i = 0; i < mr.length; ++i) 149 { 150 StringWriter sw = new StringWriter (); 151 writeMark( mr[i], sw ); 152 153 String text = sw.toString(); 154 sb.append( text.length() ). 155 append( '(' ). 156 append( text ). 157 append( ')' ); 158 } 159 sb.append( ']' ); 160 161 out.write( sb.toString() ); 162 } 163 164 165 public void readMarks( ClassRecord cr, Reader in ) 166 throws IOException 167 { 168 AnalysisModuleSet ams = cr.getAnalysisModuleSet(); 169 170 int count = ReadUtil.toInt( ReadUtil.readTo( in, ':' ) ); 171 String measureName = ReadUtil.readCount( in, count ); 172 ReadUtil.readTo( in, ',' ); 173 int markCount = ReadUtil.toInt( ReadUtil.readTo( in, '[' ) ); 174 for (int i = 0; i < markCount; ++i) 175 { 176 count = ReadUtil.toInt( ReadUtil.readTo( in, '(' ) ); 177 StringReader sr = new StringReader ( 178 ReadUtil.readCount( in, count ) ); 179 MarkRecord mr = readMark( cr, ams, sr ); 180 cr.addMark( mr ); 181 ReadUtil.readTo( in, ')' ); 182 } 183 ReadUtil.readTo( in, ']' ); 184 } 185 186 187 188 190 191 public void writeMark( MarkRecord mr, Writer out ) 192 throws IOException 193 { 194 short amIndex = mr.getAnalysisModuleIndex(); 195 short methodIndex = mr.getMethodIndex(); 196 short markIndex = mr.getMarkIndex(); 197 int lineNumber = mr.getLineNumber(); 198 IAnalysisMetaData amd = mr.getAnalysisMetaData(); 199 200 StringBuffer sb = new StringBuffer (); 201 sb.append( amIndex ). 202 append( ',' ). 203 append( methodIndex ). 204 append( ',' ). 205 append( markIndex ). 206 append( ',' ). 207 append( lineNumber ). 208 append( ',' ); 209 210 StringWriter sw = new StringWriter (); 211 AnalysisMetaDataIO amdw = new AnalysisMetaDataIO(); 212 amdw.writeAnalysisMetaData( amd, sw ); 213 String text = sw.toString(); 214 sb.append( text.length() ). 215 append( ':' ). 216 append( text ). 217 append( ',' ); 218 219 out.write( sb.toString() ); 220 } 221 222 223 public MarkRecord readMark( ClassRecord cr, AnalysisModuleSet ams, 224 Reader in ) 225 throws IOException 226 { 227 short amIndex = (short)ReadUtil.toInt( ReadUtil.readTo( in, ',' ) ); 228 short methodIndex = (short)ReadUtil.toInt( ReadUtil.readTo( in, ',' ) ); 229 short markIndex = (short)ReadUtil.toInt( ReadUtil.readTo( in, ',' ) ); 230 int lineNumber = ReadUtil.toInt( ReadUtil.readTo( in, ',' ) ); 231 int count = ReadUtil.toInt( ReadUtil.readTo( in, ':' ) ); 232 StringReader sr = new StringReader ( ReadUtil.readCount( in, count ) ); 233 AnalysisMetaDataIO amdr = new AnalysisMetaDataIO(); 234 IAnalysisMetaData amd = amdr.readAnalysisMetaData( sr ); 235 ReadUtil.readTo( in, ',' ); 236 237 return new MarkRecord( amd, 238 ams.getAnalysisModuleAt( amIndex ).getMeasureName(), 239 cr.getMethodAt( methodIndex ), 240 markIndex, lineNumber ); 241 } 242 } 243 244 | Popular Tags |