JavaPropertiesResource extends ResourceFilter { @Override public void write(OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { List<ResourceString> resStrings = languageBundle.getSortedResourceStrings(); BreakIterator brkItr = Utils.getWordBreakIterator(options); PrintWriter pw = new PrintWriter(new OutputStreamWriter(outStream, getCharset())); for (String note : languageBundle.getNotes()) { if (enc == Encoding.UTF_8) { pw.println("#" + note); } else { pw.println("#" + escapeOnlyUnicode(note)); } } if (!languageBundle.getNotes().isEmpty()) { pw.println(); } pw.println("#"+new Date().toString()); for (ResourceString res : resStrings) { String value = res.getValue(); value = escapeMessagePattern(value, msgPatEsc); PropDef pd = new PropDef(res.getKey(),value,PropDef.PropSeparator.EQUAL,res.getNotes()); pd.print(pw, brkItr, (enc == Encoding.UTF_8)); } pw.close(); } 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 testWriteAllQuotes() throws IOException, ResourceFilterException { File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".properties"); JavaPropertiesResource res = new JavaPropertiesResource(Encoding.ISO_8859_1, MessagePatternEscape.ALL); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile)) { res.write(os, WRITE_BUNDLE_ALL, null); os.flush(); assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE_ALL, tempFile, 1)); } }
@Test public void testWrite() throws IOException, ResourceFilterException { File tempFile = File.createTempFile(this.getClass().getSimpleName(), ".properties"); tempFile.deleteOnExit(); try (OutputStream os = new FileOutputStream(tempFile)) { res.write(os, WRITE_BUNDLE, null); os.flush(); assertTrue(ResourceTestUtil.compareFilesUpTo(EXPECTED_WRITE_FILE, tempFile, 5)); assertTrue(ResourceTestUtil.compareFiles(EXPECTED_WRITE_FILE, tempFile, 6)); } }