class 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);

        // Sort by bundle
        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();
    }

}