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.Writer ; 32 33 import net.sourceforge.groboutils.codecoverage.v2.IAnalysisModule; 34 import net.sourceforge.groboutils.codecoverage.v2.IMethodCode; 35 36 43 class AnalysisModuleIO 44 { 45 public AnalysisModuleIO() 46 { 47 } 49 50 51 static class StaleAnalysisModule implements IAnalysisModule 52 { 53 private String name; 54 private String unit; 55 private String mime; 56 57 public StaleAnalysisModule( String n, String u, String m ) 58 { 59 this.name = n; 60 this.unit = u; 61 this.mime = m; 62 } 63 64 public String getMeasureName() { return this.name; } 65 public String getMeasureUnit() { return this.unit; } 66 public String getMimeEncoding() { return this.mime; } 67 public void analyze( IMethodCode method ) 68 { 69 throw new IllegalStateException ( 70 "this is a stale module for measure '"+this.name+"'" ); 71 } 72 } 73 74 public void writeAnalysisModule( IAnalysisModule ams, Writer out ) 75 throws IOException 76 { 77 StringBuffer sb = new StringBuffer (); 78 79 sb.append( ams.getMeasureName().length() ). 80 append( ':' ). 81 append( ams.getMeasureName() ). 82 append( ',' ). 83 append( ams.getMeasureUnit().length() ). 84 append( ':' ). 85 append( ams.getMeasureUnit() ). 86 append( ',' ). 87 append( ams.getMimeEncoding().length() ). 88 append( ':' ). 89 append( ams.getMimeEncoding() ); 90 91 out.write( sb.toString() ); 92 } 93 94 95 99 public IAnalysisModule readAnalysisModule( Reader in ) 100 throws IOException 101 { 102 int count = ReadUtil.toInt( 103 ReadUtil.readTo( in, ':' ) ); 104 String measureName = ReadUtil.readCount( in, count ); 105 ReadUtil.readTo( in, ',' ); 106 107 count = ReadUtil.toInt( 108 ReadUtil.readTo( in, ':' ) ); 109 String measureUnit = ReadUtil.readCount( in, count ); 110 ReadUtil.readTo( in, ',' ); 111 112 count = ReadUtil.toInt( 113 ReadUtil.readTo( in, ':' ) ); 114 String mimeEncoding = ReadUtil.readCount( in, count ); 115 116 return new StaleAnalysisModule( measureName, measureUnit, 117 mimeEncoding ); 118 } 119 } 120 121 | Popular Tags |