parent
23aeba0e46
commit
a678db3888
|
|
@ -171,15 +171,15 @@ public abstract class FileCopyUtils {
|
||||||
Assert.notNull(out, "No Writer specified");
|
Assert.notNull(out, "No Writer specified");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int byteCount = 0;
|
int charCount = 0;
|
||||||
char[] buffer = new char[BUFFER_SIZE];
|
char[] buffer = new char[BUFFER_SIZE];
|
||||||
int bytesRead = -1;
|
int charsRead;
|
||||||
while ((bytesRead = in.read(buffer)) != -1) {
|
while ((charsRead = in.read(buffer)) != -1) {
|
||||||
out.write(buffer, 0, bytesRead);
|
out.write(buffer, 0, charsRead);
|
||||||
byteCount += bytesRead;
|
charCount += charsRead;
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
return byteCount;
|
return charCount;
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
close(in);
|
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.
|
* Closes the writer when done.
|
||||||
* @param in the String to copy from
|
* @param in the String to copy from
|
||||||
* @param out the Writer to copy to
|
* @param out the Writer to copy to
|
||||||
|
|
|
||||||
|
|
@ -87,9 +87,9 @@ public abstract class StreamUtils {
|
||||||
StringBuilder out = new StringBuilder();
|
StringBuilder out = new StringBuilder();
|
||||||
InputStreamReader reader = new InputStreamReader(in, charset);
|
InputStreamReader reader = new InputStreamReader(in, charset);
|
||||||
char[] buffer = new char[BUFFER_SIZE];
|
char[] buffer = new char[BUFFER_SIZE];
|
||||||
int bytesRead = -1;
|
int charsRead;
|
||||||
while ((bytesRead = reader.read(buffer)) != -1) {
|
while ((charsRead = reader.read(buffer)) != -1) {
|
||||||
out.append(buffer, 0, bytesRead);
|
out.append(buffer, 0, charsRead);
|
||||||
}
|
}
|
||||||
return out.toString();
|
return out.toString();
|
||||||
}
|
}
|
||||||
|
|
@ -127,10 +127,11 @@ public abstract class StreamUtils {
|
||||||
Assert.notNull(out, "No OutputStream specified");
|
Assert.notNull(out, "No OutputStream specified");
|
||||||
|
|
||||||
out.write(in);
|
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.
|
* <p>Leaves the stream open when done.
|
||||||
* @param in the String to copy from
|
* @param in the String to copy from
|
||||||
* @param charset the Charset
|
* @param charset the Charset
|
||||||
|
|
@ -161,7 +162,7 @@ public abstract class StreamUtils {
|
||||||
|
|
||||||
int byteCount = 0;
|
int byteCount = 0;
|
||||||
byte[] buffer = new byte[BUFFER_SIZE];
|
byte[] buffer = new byte[BUFFER_SIZE];
|
||||||
int bytesRead = -1;
|
int bytesRead;
|
||||||
while ((bytesRead = in.read(buffer)) != -1) {
|
while ((bytesRead = in.read(buffer)) != -1) {
|
||||||
out.write(buffer, 0, bytesRead);
|
out.write(buffer, 0, bytesRead);
|
||||||
byteCount += bytesRead;
|
byteCount += bytesRead;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue