class IOSStringsResource extends ResourceFilter {

    @Override
    public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options) throws IOException, ResourceFilterException {
        // put res data into a map for easier searching
        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*\".*")) { // begins with quote char
                // new entry
                StringBuilder entry = new StringBuilder(128);
                List<String> rawLines = new LinkedList<String>();

                // keep appending lines until entry termination via semi-colon
                // also keep a list of lines read so they can be written back
                // if the key is not found
                do {
                    entry.append(line.trim()).append(' ');
                    rawLines.add(line);
                } while (!line.matches(".*[^\\\\];\\s*$") && (line = reader.readLine()) != null);

                // split across " = "
                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();
    }

}