Source:
private static void copyWithFilterSets(final Resource source, final Resource dest, final FilterSetCollection filters, final Vector filterChains, final boolean filterChainsAvailable, final boolean append, final String inputEncoding, final String outputEncoding, final Project project) throws IOException { if (source instanceof FileResource && dest instanceof FileResource) { if (areSame((FileResource) source, (FileResource) dest)) { log(project, "Skipping (self) copy of " + source + " to " + dest); return; } } BufferedReader in = null; BufferedWriter out = null; try { InputStreamReader isr = null; if (inputEncoding == null) { isr = new InputStreamReader(source.getInputStream()); } else { isr = new InputStreamReader(source.getInputStream(), inputEncoding); } in = new BufferedReader(isr); final OutputStream os = getOutputStream(dest, append, project); OutputStreamWriter osw; if (outputEncoding == null) { osw = new OutputStreamWriter(os); } else { osw = new OutputStreamWriter(os, outputEncoding); } out = new BufferedWriter(osw); if (filterChainsAvailable) { final ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(FileUtils.BUF_SIZE); crh.setPrimaryReader(in); crh.setFilterChains(filterChains); crh.setProject(project); final Reader rdr = crh.getAssembledReader(); in = new BufferedReader(rdr); } final LineTokenizer lineTokenizer = new LineTokenizer(); lineTokenizer.setIncludeDelims(true); String newline = null; String line = lineTokenizer.getToken(in); while (line != null) { if (line.length() == 0) { out.newLine(); } else { newline = filters.replaceTokens(line); out.write(newline); } line = lineTokenizer.getToken(in); } } finally { FileUtils.close(out); FileUtils.close(in); } }

Target:
private static void copyWithFilterSets(final Resource source, final Resource dest, final FilterSetCollection filters, final Vector filterChains, final boolean filterChainsAvailable, final boolean append, final String inputEncoding, final String outputEncoding, final Project project) throws IOException { if (areSame(source, dest)) { log(project, "Skipping (self) copy of " + source + " to " + dest); return; } BufferedReader in = null; BufferedWriter out = null; try { InputStreamReader isr = null; if (inputEncoding == null) { isr = new InputStreamReader(source.getInputStream()); } else { isr = new InputStreamReader(source.getInputStream(), inputEncoding); } in = new BufferedReader(isr); final OutputStream os = getOutputStream(dest, append, project); OutputStreamWriter osw; if (outputEncoding == null) { osw = new OutputStreamWriter(os); } else { osw = new OutputStreamWriter(os, outputEncoding); } out = new BufferedWriter(osw); if (filterChainsAvailable) { final ChainReaderHelper crh = new ChainReaderHelper(); crh.setBufferSize(FileUtils.BUF_SIZE); crh.setPrimaryReader(in); crh.setFilterChains(filterChains); crh.setProject(project); final Reader rdr = crh.getAssembledReader(); in = new BufferedReader(rdr); } final LineTokenizer lineTokenizer = new LineTokenizer(); lineTokenizer.setIncludeDelims(true); String newline = null; String line = lineTokenizer.getToken(in); while (line != null) { if (line.length() == 0) { out.newLine(); } else { newline = filters.replaceTokens(line); out.write(newline); } line = lineTokenizer.getToken(in); } } finally { FileUtils.close(out); FileUtils.close(in); } }