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.IAnalysisModule; 36 37 44 class AnalysisModuleSetIO 45 { 46 public AnalysisModuleSetIO() 47 { 48 } 50 51 52 public void writeAnalysisModuleSet( AnalysisModuleSet ams, Writer out ) 53 throws IOException 54 { 55 AnalysisModuleIO amw = new AnalysisModuleIO(); 56 57 StringBuffer sb = new StringBuffer (); 58 59 int count = ams.getAnalysisModuleCount(); 60 sb.append( count ).append( '{' ); 61 for (short i = 0; i < count; ++i) 62 { 63 StringWriter sw = new StringWriter (); 64 amw.writeAnalysisModule( ams.getAnalysisModuleAt( i ), sw ); 65 String text = sw.toString(); 66 sb.append( '[' ).append( i ).append( ';' ). 67 append( text.length() ).append( ';' ).append( text ). 68 append( ']' ); 69 } 70 sb.append( '}' ); 71 72 out.write( sb.toString() ); 73 } 74 75 76 public AnalysisModuleSet readAnalysisModuleSet( Reader in ) 77 throws IOException 78 { 79 AnalysisModuleIO amr = new AnalysisModuleIO(); 80 81 int count = ReadUtil.toInt( ReadUtil.readTo( in, '{' ) ); 82 AnalysisModuleSet ams = new AnalysisModuleSet(); 83 for (int i = 0; i < count; ++i) 84 { 85 ReadUtil.readTo( in, '[' ); 86 int index = ReadUtil.toInt( ReadUtil.readTo( in, ';' ) ); 87 if (i != index) 88 { 89 throw new IOException ( "Expected to find index "+i+ 90 ", but found "+index+"." ); 91 } 92 int size = ReadUtil.toInt( ReadUtil.readTo( in, ';' ) ); 93 StringReader sr = new StringReader ( 94 ReadUtil.readCount( in, size ) ); 95 IAnalysisModule am = amr.readAnalysisModule( sr ); 96 ams.addAnalysisModule( am ); 97 ReadUtil.readTo( in, ']' ); 98 } 99 ReadUtil.readTo( in, '}' ); 100 101 return ams; 102 } 103 } 104 105 | Popular Tags |