CSVFilter extends ResourceFilter { @Override public void write(OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8)); CSVPrinter printer = CSVFormat.RFC4180.withHeader("key", "value").print(writer); for (ResourceString resString : languageBundle.getSortedResourceStrings()) { printer.printRecord(resString.getKey(), resString.getValue()); } printer.flush(); }  @Override LanguageBundle parse(InputStream inStream, FilterOptions options); @Override void write(OutputStream outStream, LanguageBundle languageBundle, FilterOptions options); @Override void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options); static final String ID; static final Type TYPE; }
@Test public void testWrite() { TestResourceStringData[] testData = { new TestResourceStringData("minestrone", "Minestrone", 2), new TestResourceStringData("pizza", "Pizza", 3), new TestResourceStringData("spaghetti", "Spaghetti", 1) }; String[] expectedLines = { "key,value", "spaghetti,Spaghetti", "minestrone,Minestrone", "pizza,Pizza" }; LanguageBundle bundle = TestUtils.createLanguageBundle(testData); ResourceFilter filter = ResourceFilterFactory.getResourceFilter(CSVFilter.ID); try (ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { filter.write(outStream, bundle, new FilterOptions(Locale.ENGLISH)); TestUtils.compareLines(expectedLines, outStream.toByteArray()); } catch (IOException e) { fail(e.getMessage()); } catch (ResourceFilterException e) { fail(e.getMessage()); } }