class CSVFilter extends ResourceFilter {

    @Override
    public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options) throws IOException, ResourceFilterException {
        // create key-value map
        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();
    }

}