/** ** Apply replacements/conditionals and write output */ public static void writeOutputSource(String inputSource, File outputFile) throws IOException { String outputSource = inputSource; if (StringTools.isBlank(outputSource)) { // throw new IOException("Output Source is empty"); return; } /* custom map */ Map<String, String> customMap = new HashMap<String, String>() { @Override public String get(Object key) { String ks = StringTools.trim(key); if (ks.toLowerCase().endsWith(".md5")) { String K = ks.substring(0, ks.length() - ".md5".length()); String V = RTConfig._getString(K, null, true /*dftOK*/); if (V != null) { return StringTools.trim(FileTools.getHash_MD5(V.getBytes())).toUpperCase(); } else { return null; } } else { return null; } } }; /* replace standard runtime vars in text (ie. %{var=value}) */ // -- replace %{var=value} outputSource = RTConfig.insertKeyValues(outputSource, STR_DELIM, END_DELIM, DFT_DELIM, customMap); // -- replace /#{var=value}#/ outputSource = RTConfig.insertKeyValues(outputSource, STR_CDELIM, END_CDELIM, DFT_CDELIM, customMap); /* conditional code? */ outputSource = CompiletimeVars.getConditionalSource(outputSource); /* write output */ if (outputFile != null) { Print.sysPrintln("Output to file: " + outputFile); boolean didWrite = FileTools.writeFile(outputSource.getBytes(), outputFile); if (!didWrite) { throw new IOException("Unable to write output file."); } } else { // -- write to stdout Print.sysPrintln(outputSource); } }
/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub FileTools fileTools = new FileTools(); List<String> filePaths = fileTools.getAllFileDirectory( "/Users/gaochuanjun/Documents/12.新闻app性能测试/01.性能测试/02.20140523"); for (String filePath : filePaths) { System.out.println(filePath); } List<AggregateReport> aggregateReports = fileTools.getContent(filePaths); for (AggregateReport aggregateReport : aggregateReports) { System.out.println( aggregateReport.getThreads() + "," + aggregateReport.getLabel() + "," + aggregateReport.getSamples() + "," + aggregateReport.getAverage() + "," + aggregateReport.getMedian() + "," + aggregateReport.getNinetyLine() + "," + aggregateReport.getMin() + "," + aggregateReport.getMax() + "," + aggregateReport.getError() + "," + aggregateReport.getThroughput()); } fileTools.writeFile( "/Users/gaochuanjun/Documents/12.新闻app性能测试/01.性能测试/02.20140523/result.csv", aggregateReports); }