Author: dkulp
Date: Tue Oct 2 18:50:19 2012
New Revision: 1393095
URL: http://svn.apache.org/viewvc?rev=1393095&view=rev
Log:
[CXF-4533] Use a Reader to read from the input stream as chars instead of
trying to handle it ourselves.
Modified:
cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
Modified: cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?rev=1393095&r1=1393094&r2=1393095&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java Tue
Oct 2 18:50:19 2012
@@ -28,9 +28,11 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -310,21 +312,23 @@ public class CachedOutputStream extends
} else {
// read the file
FileInputStream fin = new FileInputStream(tempFile);
- byte bytes[] = new byte[1024];
- long x = fin.read(bytes);
+ Reader reader = new InputStreamReader(fin, charsetName);
+ char bytes[] = new char[1024];
+ long x = reader.read(bytes);
while (x != -1) {
if ((count + x) > limit) {
x = limit - count;
}
- out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0,
(int)x));
+ out.append(bytes, 0, (int)x);
count += x;
if (count >= limit) {
x = -1;
} else {
- x = fin.read(bytes);
+ x = reader.read(bytes);
}
}
+ reader.close();
fin.close();
}
}
@@ -348,12 +352,14 @@ public class CachedOutputStream extends
} else {
// read the file
FileInputStream fin = new FileInputStream(tempFile);
- byte bytes[] = new byte[1024];
- int x = fin.read(bytes);
+ Reader reader = new InputStreamReader(fin, charsetName);
+ char bytes[] = new char[1024];
+ int x = reader.read(bytes);
while (x != -1) {
- out.append(IOUtils.newStringFromBytes(bytes, charsetName, 0,
x));
- x = fin.read(bytes);
+ out.append(bytes, 0, x);
+ x = reader.read(bytes);
}
+ reader.close();
fin.close();
}
}