JavaPropertiesResource 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 baseReader = new BufferedReader(new InputStreamReader(baseStream, getCharset())); PrintWriter outWriter = new PrintWriter(new OutputStreamWriter(outStream, getCharset())); BreakIterator brkItr = Utils.getWordBreakIterator(options); String line = null; StringBuilder logicalLineBuf = new StringBuilder(); List<String> orgLines = new ArrayList<String>(8); do { String logicalLine = null; line = baseReader.readLine(); if (line == null) { if (!orgLines.isEmpty()) { logicalLine = logicalLineBuf.toString(); } } else { String normLine = stripLeadingSpaces(line); if (orgLines.isEmpty()) { if (normLine.startsWith("#") || normLine.startsWith("!")) { outWriter.println(line); } else if (isContinuationLine(normLine)) { logicalLineBuf.append(normLine, 0, normLine.length() - 1); orgLines.add(line); } else { logicalLine = line; } } else { if (normLine.endsWith("\\")) { logicalLineBuf.append(normLine.substring(0, normLine.length() - 1)); orgLines.add(line); } else { logicalLineBuf.append(normLine); orgLines.add(line); logicalLine = logicalLineBuf.toString(); } } } if (logicalLine != null) { PropDef pd = PropDef.parseLine(logicalLine); if (pd != null && kvMap.containsKey(pd.getKey())) { String firstLine = orgLines.isEmpty() ? line : orgLines.get(0); int len = getLeadingSpacesLength(firstLine); if (len > 0) { outWriter.print(firstLine.substring(0, len)); } String key = pd.getKey(); String value = escapeMessagePattern(kvMap.get(key), msgPatEsc); PropDef modPd = new PropDef(key, value , pd.getSeparator(), null); modPd.print(outWriter, brkItr, (enc == Encoding.UTF_8)); } else { if (orgLines.isEmpty()) { outWriter.println(line); } else { for (String orgLine : orgLines) { outWriter.println(orgLine); } } } orgLines.clear(); logicalLineBuf.setLength(0); } } while (line != null); outWriter.flush(); } JavaPropertiesResource(Encoding enc, MessagePatternEscape msgPatEsc);  JavaPropertiesResource(); @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 = File.createTempFile(this.getClass().getSimpleName(), ".properties"); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile); InputStream is = new FileInputStream(INPUT_FILE)) { res.merge(is, os, WRITE_BUNDLE, new FilterOptions(Locale.ENGLISH)); os.flush(); assertTrue(ResourceTestUtil.compareFiles(EXPECTED_MERGE_FILE, tempFile)); } }