class XLIFFResource extends ResourceFilter {

    @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)
     */
    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());

        // TODO: We should use xml encoding declaration, instead of hardcoding
        // "UTF-8"
        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];

                // +2 for source and source block
                String whiteSpace = line.substring(0, line.indexOf("<")) + "  ";

                // writes key line
                while (!line.matches(end_source_pattern)) {
                    outStream.write(line.getBytes());
                    line = in.nextLine() + '\n';
                }

                outStream.write(line.getBytes());
                // TODO: Instead of linear search resource key every time,
                // we may create hash map first.

                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();
    }

}