POTResource extends ResourceFilter { @Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { Map<String, String> kvMap = Utils.createKeyValueMap(languageBundle.getResourceStrings()); BufferedReader reader = new BufferedReader(new InputStreamReader(baseStream, CHAR_SET)); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, CHAR_SET)); BreakIterator brkItr = Utils.getWordBreakIterator(options); String line; while ((line = reader.readLine()) != null) { if (line.startsWith(UNTRANSLATED_STRING_PREFIX)) { String key = extractMessage(line, reader); do { writer.write(line); writer.newLine(); } while ((line = reader.readLine()) != null && line.trim().startsWith("\"")); if (!line.startsWith(TRANSLATED_STRING_PREFIX) || key == null || key.isEmpty() || !kvMap.containsKey(key) || kvMap.get(key) == null) { do { writer.write(line); writer.newLine(); } while ((line = reader.readLine()) != null && !line.isEmpty()); if (line != null && line.isEmpty()) { writer.newLine(); } } else { writer.write(formatMessage(TRANSLATED_STRING_PREFIX, kvMap.get(key), brkItr)); writer.newLine(); while ((line = reader.readLine()) != null && !line.isEmpty()) ; } } else { writer.write(line); writer.newLine(); } } writer.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);  }
@Test public void testMerge() throws IOException, ResourceFilterException { File tempFile; tempFile = File.createTempFile(this.getClass().getSimpleName(), ".pot"); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile); InputStream is = new FileInputStream(MERGE_INPUT_1_FILE)) { res.merge(is, os, MERGE_BUNDLE, new FilterOptions(Locale.ENGLISH)); os.flush(); assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_1_FILE, tempFile)); } tempFile = File.createTempFile(this.getClass().getSimpleName(), ".pot"); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile); InputStream is = new FileInputStream(MERGE_INPUT_2_FILE)) { res.merge(is, os, MERGE_BUNDLE, new FilterOptions(Locale.JAPANESE)); os.flush(); assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_2_FILE, tempFile)); } }