You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2007/01/20 01:53:07 UTC
svn commit: r498022 -
/incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java
Author: schor
Date: Fri Jan 19 16:53:07 2007
New Revision: 498022
URL: http://svn.apache.org/viewvc?view=rev&rev=498022
Log:
UIMA-210 Changed xxx.read(buffer) in many places to insure
all bytes/chars are read. Sometimes the read was wrapped in
a while loop. Othertimes, I substituted BufferedXXX for the
non buffered readers/input-streams. The .read(buf) for the
buffered versions has the "while loop" built in, according to
the javadocs. For BufferedReader, I used the form
.read(buf, 0, length) as that was the only form that the
javadoc said it did this for.
Modified:
incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java
Modified: incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java?view=diff&rev=498022&r1=498021&r2=498022
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-test-util/src/main/java/org/apache/uima/test/junit_extension/FileCompare.java Fri Jan 19 16:53:07 2007
@@ -255,16 +255,18 @@
* sure what the best way of handling this is.
*/
public static String file2String(File file) throws IOException {
+ BufferedReader bReader = new BufferedReader(new FileReader(file));
+ int length = (int)file.length();
// Read the file into a string using a char buffer.
- char[] buf = new char[10000];
- int charsRead;
- BufferedReader reader = new BufferedReader(new FileReader(file));
- StringBuffer strbuf = new StringBuffer();
- while ((charsRead = reader.read(buf)) >= 0) {
- strbuf.append(buf, 0, charsRead);
+ char[] buf = new char[length];
+ try {
+ // will read all the chars of the file, calling read repeatedly
+ // as needed in the underlying layer
+ // Note: this 3 argument version is the only one documented to do this.
+ bReader.read(buf, 0, length);
+ } finally {
+ bReader.close();
}
- reader.close();
- final String text = strbuf.toString();
- return text;
+ return new String(buf);
}
}