Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ public static int copy(Reader in, Writer out) throws IOException {
Assert.notNull(in, "No Reader specified");
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 {
try {
Expand All @@ -199,7 +199,7 @@ public static int copy(Reader in, Writer out) throws IOException {
}

/**
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static String copyToString(InputStream in, Charset charset) throws IOExce
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();
}
Expand All @@ -87,10 +87,11 @@ public static void copy(byte[] in, OutputStream out) throws IOException {
Assert.notNull(in, "No input byte array specified");
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
Expand Down Expand Up @@ -119,7 +120,7 @@ public static int copy(InputStream in, OutputStream out) throws IOException {
Assert.notNull(out, "No OutputStream specified");
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;
Expand Down