Closes gh-880
This commit is contained in:
izeye 2015-10-03 15:27:25 +09:00 committed by Brian Clozel
parent 23aeba0e46
commit a678db3888
2 changed files with 13 additions and 12 deletions

View File

@ -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

View File

@ -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.
* <p>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;