private void writeJVMStatisticsResults(OutputStreamWriter outputStreamWriter) throws IOException { List<JVMResourcesRecord> unwrittenResults = this.jvmStatistics; this.jvmStatistics = initMatchedJVMStatisticsResultContainer(); Iterator<JVMResourcesRecord> iterator = unwrittenResults.iterator(); while (iterator.hasNext()) { JVMResourcesRecord record = iterator.next(); String resultString = record.writeData().toString(); outputStreamWriter.write(resultString); } }
public void writeJVMStatistics(String filenameJVMStatistics) { FileOutputStream outputStream = null; OutputStreamWriter outputStreamWriter = null; try { outputStream = new FileOutputStream(filenameJVMStatistics, true); outputStreamWriter = new OutputStreamWriter(outputStream); if (new File(filenameJVMStatistics).length() <= 0) outputStreamWriter.write(JVMResourcesRecord.writeHeader().toString()); writeJVMStatisticsResults(outputStreamWriter); } catch (IOException e) { log.error("error writing JVM statistic results to file " + filenameJVMStatistics, e); } finally { try { if (outputStreamWriter != null) outputStreamWriter.close(); if (outputStream != null) outputStream.close(); log.info( "postage JVM statistic results completely written to file " + filenameJVMStatistics); } catch (IOException e) { log.error("error closing stream", e); } } }