MetadataWriter implements StatisticsOutputter { @Override public void initialiseOutput(StatisticsOutputContext statisticsOutputContext) { printStream.append("# BEAM Statistics export\n") .append("#\n") .append("# Products:\n"); for (String sourceProductName : statisticsOutputContext.sourceProductNames) { printStream.append("# ") .append(sourceProductName) .append("\n"); } if (statisticsOutputContext.startDate != null) { printStream .append("#\n") .append("# Start Date: ") .append(statisticsOutputContext.startDate.format()) .append("\n"); } if (statisticsOutputContext.endDate != null) { printStream .append("#\n") .append("# End Date: ") .append(statisticsOutputContext.endDate.format()) .append("\n"); } printStream.append("#\n"); printStream.append("# Regions:\n"); for (String regionId : statisticsOutputContext.regionIds) { printStream.append("# ") .append(regionId) .append("\n"); } } MetadataWriter(PrintStream printStream); @Override void initialiseOutput(StatisticsOutputContext statisticsOutputContext); @Override void addToOutput(String bandName, String regionId, Map<String, Number> statistics); @Override void finaliseOutput();  }
@Test public void testWriteMetadata() throws ParseException { final Product[] sourceProducts = {new Product("MER_RR__2PBCMsomething", "type", 10, 10)}; final ProductData.UTC startDate = ProductData.UTC.parse("2010-01-01", "yyyy-MM-dd"); final ProductData.UTC endDate = ProductData.UTC.parse("2011-01-01", "yyyy-MM-dd"); final String[] regionIds = {"bullerbue", "bielefeld"}; metadataWriter.initialiseOutput(StatisticsOutputContext.create(sourceProducts, null, null, startDate, endDate, regionIds)); assertEquals("# BEAM Statistics export\n" + "#\n" + "# Products:\n" + "# MER_RR__2PBCMsomething\n" + "#\n" + "# Start Date: 01-JAN-2010 00:00:00.000000\n" + "#\n" + "# End Date: 01-JAN-2011 00:00:00.000000\n" + "#\n" + "# Regions:\n" + "# bullerbue\n" + "# bielefeld\n" , outputStream.toString()); }