XLIFFResource extends ResourceFilter { @Override @Deprecated public void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle, FilterOptions options) throws IOException, ResourceFilterException { String targetLanguage = languageBundle.getEmbeddedLanguageCode(); if (targetLanguage == null || targetLanguage.isEmpty()) { throw new ResourceFilterException("Target language is not specified."); } Map<String, String> kvMap = Utils.createKeyValueMap(languageBundle.getResourceStrings()); Scanner in = new Scanner(baseStream, "UTF-8"); String line = ""; String key_pattern = "^.*<unit.*id=\".*\">\n$"; String end_source_pattern = ".*</source>\n$"; while (in.hasNextLine()) { line = in.nextLine() + '\n'; if (!line.matches(key_pattern)) { if (line.indexOf("<xliff") != -1) { StringBuilder newline = new StringBuilder(100); newline.append("<xliff version=\"2.0\" srcLang=\"en\" targLang=\"").append(targetLanguage).append("\">"); line = newline.toString(); } outStream.write(line.getBytes()); } else { String[] wordList = line.split("\""); String key = wordList[1]; String whiteSpace = line.substring(0, line.indexOf("<")) + " "; while (!line.matches(end_source_pattern)) { outStream.write(line.getBytes()); line = in.nextLine() + '\n'; } outStream.write(line.getBytes()); if (kvMap.containsKey(key)) { String value = kvMap.get(key); final int character_offset = 80; BreakIterator b = BreakIterator.getWordInstance(); b.setText(value); int offset = 80; int start = 0; boolean first = true; StringBuilder temp = new StringBuilder(100); temp.append(whiteSpace).append("<target>"); while (start < value.length()) { if (value.length() > character_offset) { if (!first) { temp.append(whiteSpace).append(" "); } first = false; int end = b.following(offset); String str = value.substring(start, end); start = end; offset += 80; temp.append(str).append(" \\\n"); } else { temp.append(value); start = value.length(); } } if (value.length() > character_offset) { temp.append(whiteSpace); } temp.append("</target>\n"); outStream.write(temp.toString().getBytes()); } else { outStream.write(line.getBytes()); } } } in.close(); }  @Override LanguageBundle parse(InputStream inStream, FilterOptions options); @Override void write(OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options); @Override @Deprecated /* * This method is incomplete and may not produce the expected output. * * (non-Javadoc) * @see com.ibm.g11n.pipeline.resfilter.ResourceFilter#merge(java.io.InputStream, java.io.OutputStream, java.lang.String, java.util.Collection) */ void merge(InputStream baseStream, OutputStream outStream, LanguageBundle languageBundle,
            FilterOptions options);  }
@SuppressWarnings("deprecation") @Test public void testMerge() throws IOException, ResourceFilterException { File tempFile; tempFile = File.createTempFile(this.getClass().getSimpleName(), ".xlf"); 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(); } tempFile = File.createTempFile(this.getClass().getSimpleName(), ".xlf"); 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(); } }