private static void copyUsingStreams(final Resource source, final Resource dest, final boolean append, final Project project) throws IOException { if (areSame(source, dest)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + source + " to " + dest); return; } try (InputStream in = source.getInputStream(); OutputStream out = getOutputStream(dest, append, project)) { final byte[] buffer = new byte[FileUtils.BUF_SIZE]; int count = 0; do { out.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); } }
private static void copyWithFilterChainsOrTranscoding(final Resource source, final Resource dest, final Vector<FilterChain> filterChains, final boolean append, final String inputEncoding, final String outputEncoding, final Project project) throws IOException { if (areSame(source, dest)) { // copying the "same" file to itself will corrupt the file, so we skip it log(project, "Skipping (self) copy of " + source + " to " + dest); return; } try (Reader in = filterWith(project, inputEncoding, filterChains, source.getInputStream()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( getOutputStream(dest, append, project), charsetFor(outputEncoding)))) { final char[] buffer = new char[FileUtils.BUF_SIZE]; while (true) { final int nRead = in.read(buffer, 0, buffer.length); if (nRead == -1) { break; } out.write(buffer, 0, nRead); } } }
source.getInputStream()); BufferedWriter out = new BufferedWriter(new OutputStreamWriter( getOutputStream(dest, append, project), charsetFor(outputEncoding)))) {