IOSStringsResource extends ResourceFilter { @Override public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { Map<String, ResourceString> resMap = Utils.createResourceStringMap(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.matches("^\\s*\".*")) { StringBuilder entry = new StringBuilder(128); List<String> rawLines = new LinkedList<String>(); do { entry.append(line.trim()).append(' '); rawLines.add(line); } while (!line.matches(".*[^\\\\];\\s*$") && (line = reader.readLine()) != null); String[] parts = entry.toString().split("\"\\s*=\\s*\""); String key = parts[0].substring(parts[0].indexOf('"') + 1).trim(); if (!resMap.containsKey(key)) { for (String rawLine : rawLines) { writer.write(rawLine); } writer.newLine(); continue; } writer.write(formatEntry(key, resMap.get(key).getValue(), resMap.get(key).getNotes(), brkItr)); } 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(), ".strings"); 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(), ".strings"); 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)); } }