MultiBundleCSVFilter extends MultiBundleResourceFilter { @Override public void write(OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options) throws IOException, ResourceFilterException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8)); CSVPrinter printer = CSVFormat.RFC4180.withHeader("module", "key", "value").print(writer); TreeMap<String, LanguageBundle> sortedBundles = new TreeMap<>(languageBundles); for (Entry<String, LanguageBundle> bundleEntry: sortedBundles.entrySet()) { String module = bundleEntry.getKey(); LanguageBundle languageBundle = bundleEntry.getValue(); for (ResourceString resString : languageBundle.getSortedResourceStrings()) { printer.printRecord(module, resString.getKey(), resString.getValue()); } } printer.flush(); }  @Override Map<String, LanguageBundle> parse(InputStream inStream, FilterOptions options); @Override void write(OutputStream outStream, Map<String, LanguageBundle> languageBundles, FilterOptions options); @Override void merge(InputStream baseStream, OutputStream outStream, Map<String, LanguageBundle> languageBundles,
            FilterOptions options); static final String ID; static final Type TYPE; }
@Test public void testWrite() { TestResourceStringData[] testDataJapanese = { new TestResourceStringData("sushi", "Sushi", 1), new TestResourceStringData("ramen", "Ramen", 2) }; TestResourceStringData[] testDataItalian = { new TestResourceStringData("minestrone", "Minestrone", 2), new TestResourceStringData("pizza", "Pizza", 3), new TestResourceStringData("spaghetti", "Spaghetti", 1) }; String[] expectedLines = { "module,key,value", "Italian Foods,spaghetti,Spaghetti", "Italian Foods,minestrone,Minestrone", "Italian Foods,pizza,Pizza", "Japanese Foods,sushi,Sushi", "Japanese Foods,ramen,Ramen" }; Map<String, LanguageBundle> testDataMap = new LinkedHashMap<>(); testDataMap.put("Japanese Foods", TestUtils.createLanguageBundle(testDataJapanese)); testDataMap.put("Italian Foods", TestUtils.createLanguageBundle(testDataItalian)); MultiBundleResourceFilter filter = ResourceFilterFactory.getMultiBundleResourceFilter(MultiBundleCSVFilter.ID); try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { filter.write(outStream, testDataMap, new FilterOptions(Locale.ENGLISH)); TestUtils.compareLines(expectedLines, outStream.toByteArray()); } catch (IOException e) { fail(e.getMessage()); } catch (ResourceFilterException e) { fail(e.getMessage()); } }