Polishing

This commit is contained in:
Juergen Hoeller
2020-06-23 11:35:22 +02:00
parent c4326cb0f5
commit 9e12a20324
6 changed files with 26 additions and 21 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();
}
@@ -130,7 +130,7 @@ public abstract class StreamUtils {
}
/**
* 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 +161,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;