diff --git a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java index 620d27daa7..de807fe5ac 100644 --- a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java +++ b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java @@ -171,15 +171,15 @@ public abstract class FileCopyUtils { Assert.notNull(out, "No Writer specified"); try { - int byteCount = 0; + int charCount = 0; char[] buffer = new char[BUFFER_SIZE]; - int bytesRead = -1; - while ((bytesRead = in.read(buffer)) != -1) { - out.write(buffer, 0, bytesRead); - byteCount += bytesRead; + int charsRead; + while ((charsRead = in.read(buffer)) != -1) { + out.write(buffer, 0, charsRead); + charCount += charsRead; } out.flush(); - return byteCount; + return charCount; } finally { close(in); @@ -188,7 +188,7 @@ public abstract class FileCopyUtils { } /** - * Copy the contents of the given String to the given output Writer. + * Copy the contents of the given String to the given Writer. * Closes the writer when done. * @param in the String to copy from * @param out the Writer to copy to diff --git a/spring-core/src/main/java/org/springframework/util/StreamUtils.java b/spring-core/src/main/java/org/springframework/util/StreamUtils.java index bcd408ee77..59425ae670 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -87,9 +87,9 @@ public abstract class StreamUtils { StringBuilder out = new StringBuilder(); InputStreamReader reader = new InputStreamReader(in, charset); char[] buffer = new char[BUFFER_SIZE]; - int bytesRead = -1; - while ((bytesRead = reader.read(buffer)) != -1) { - out.append(buffer, 0, bytesRead); + int charsRead; + while ((charsRead = reader.read(buffer)) != -1) { + out.append(buffer, 0, charsRead); } return out.toString(); } @@ -127,10 +127,11 @@ public abstract class StreamUtils { Assert.notNull(out, "No OutputStream specified"); out.write(in); + out.flush(); } /** - * Copy the contents of the given String to the given output OutputStream. + * Copy the contents of the given String to the given OutputStream. *
Leaves the stream open when done. * @param in the String to copy from * @param charset the Charset @@ -161,7 +162,7 @@ public abstract class StreamUtils { int byteCount = 0; byte[] buffer = new byte[BUFFER_SIZE]; - int bytesRead = -1; + int bytesRead; while ((bytesRead = in.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); byteCount += bytesRead;