Skip to content

Commit a678db3

Browse files
izeyebclozel
authored andcommitted
Polish
Closes gh-880
1 parent 23aeba0 commit a678db3

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

spring-core/src/main/java/org/springframework/util/FileCopyUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ public static int copy(Reader in, Writer out) throws IOException {
171171
Assert.notNull(out, "No Writer specified");
172172

173173
try {
174-
int byteCount = 0;
174+
int charCount = 0;
175175
char[] buffer = new char[BUFFER_SIZE];
176-
int bytesRead = -1;
177-
while ((bytesRead = in.read(buffer)) != -1) {
178-
out.write(buffer, 0, bytesRead);
179-
byteCount += bytesRead;
176+
int charsRead;
177+
while ((charsRead = in.read(buffer)) != -1) {
178+
out.write(buffer, 0, charsRead);
179+
charCount += charsRead;
180180
}
181181
out.flush();
182-
return byteCount;
182+
return charCount;
183183
}
184184
finally {
185185
close(in);
@@ -188,7 +188,7 @@ public static int copy(Reader in, Writer out) throws IOException {
188188
}
189189

190190
/**
191-
* Copy the contents of the given String to the given output Writer.
191+
* Copy the contents of the given String to the given Writer.
192192
* Closes the writer when done.
193193
* @param in the String to copy from
194194
* @param out the Writer to copy to

spring-core/src/main/java/org/springframework/util/StreamUtils.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public static String copyToString(@Nullable InputStream in, Charset charset) thr
8787
StringBuilder out = new StringBuilder();
8888
InputStreamReader reader = new InputStreamReader(in, charset);
8989
char[] buffer = new char[BUFFER_SIZE];
90-
int bytesRead = -1;
91-
while ((bytesRead = reader.read(buffer)) != -1) {
92-
out.append(buffer, 0, bytesRead);
90+
int charsRead;
91+
while ((charsRead = reader.read(buffer)) != -1) {
92+
out.append(buffer, 0, charsRead);
9393
}
9494
return out.toString();
9595
}
@@ -127,10 +127,11 @@ public static void copy(byte[] in, OutputStream out) throws IOException {
127127
Assert.notNull(out, "No OutputStream specified");
128128

129129
out.write(in);
130+
out.flush();
130131
}
131132

132133
/**
133-
* Copy the contents of the given String to the given output OutputStream.
134+
* Copy the contents of the given String to the given OutputStream.
134135
* <p>Leaves the stream open when done.
135136
* @param in the String to copy from
136137
* @param charset the Charset
@@ -161,7 +162,7 @@ public static int copy(InputStream in, OutputStream out) throws IOException {
161162

162163
int byteCount = 0;
163164
byte[] buffer = new byte[BUFFER_SIZE];
164-
int bytesRead = -1;
165+
int bytesRead;
165166
while ((bytesRead = in.read(buffer)) != -1) {
166167
out.write(buffer, 0, bytesRead);
167168
byteCount += bytesRead;

0 commit comments

Comments
 (0)