CSVFilter extends ResourceFilter { @Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { Map<String, String> kvMap = new HashMap<String, String>(); for (ResourceString resString : languageBundle.getResourceStrings()) { kvMap.put(resString.getKey(), resString.getValue()); } CSVParser parser = CSVParser.parse(baseStream, StandardCharsets.UTF_8, CSVFormat.RFC4180.withHeader("key", "value").withSkipHeaderRecord(true)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8)); CSVPrinter printer = CSVFormat.RFC4180.withHeader("key", "value").print(writer); for (CSVRecord record : parser) { String key = record.get(0); String value = record.get(1); String trValue = kvMap.get(key); if (trValue != null) { value = trValue; } printer.printRecord(key, value); } 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 testMerge() { String[] baseLines = { "key,value", "spaghetti,Spaghetti", "minestrone,Minestrone", "pizza,Pizza" }; TestResourceStringData[] testData = { new TestResourceStringData("pizza", "ピザ", 1), new TestResourceStringData("spaghetti", "スパゲッティ", 2), new TestResourceStringData("calzone", "カルゾーン", 3) }; String[] expectedLines = { "key,value", "spaghetti,スパゲッティ", "minestrone,Minestrone", "pizza,ピザ" }; LanguageBundle bundle = TestUtils.createLanguageBundle(testData); ResourceFilter filter = ResourceFilterFactory.getResourceFilter(CSVFilter.ID); try (InputStream baseStream = TestUtils.creteInputStream(baseLines); ByteArrayOutputStream outStream = new ByteArrayOutputStream()) { filter.merge(baseStream, outStream, bundle, new FilterOptions(Locale.JAPANESE)); TestUtils.compareLines(expectedLines, outStream.toByteArray()); } catch (IOException e) { fail(e.getMessage()); } catch (ResourceFilterException e) { fail(e.getMessage()); } }