You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Anthony Green <gr...@redhat.com> on 2006/07/14 08:53:01 UTC
[Patch] Fix commons-io test code
This support routine from the commons-io project test code assumed that
FileReader.read(byte[]) would always read the entire file. There's no
such guarantee, and some tests were failing on GNU Classpath based VMs
because of this.
Thanks,
AG
--- src/test/org/apache/commons/io/testtools/FileBasedTestCase.java~ 2006-07-13 23:44:13.000000000 -0700
+++ src/test/org/apache/commons/io/testtools/FileBasedTestCase.java 2006-07-13 23:44:20.000000000 -0700
@@ -167,18 +171,22 @@
throws IOException
{
Reader ir = new java.io.FileReader( file );
- try {
- char[] c1 = new char[ c0.length ];
- int numRead = ir.read( c1 );
- assertTrue( "Different number of bytes", numRead == c0.length );
- for( int i = 0;
- i < numRead;
- assertTrue( "Byte " + i + " differs (" + c0[ i ] + " != " + c1[ i ] + ")",
- c0[ i ] == c1[ i ] ), i++
- );
- } finally {
- ir.close();
- }
+ int count = 0, numRead = 0;
+ char[] c1 = new char[ c0.length ];
+ try {
+ while (count < c0.length)
+ {
+ numRead = ir.read( c1, count, c0.length);
+ for( int i = count;
+ i < count+numRead;
+ assertTrue( "Byte " + i + " differs (" + c0[ i ] + " != " + c1[ i ] + ")",
+ c0[ i ] == c1[ i ] ), i++
+ );
+ count += numRead;
+ }
+ } finally {
+ ir.close();
+ }
}
protected void checkWrite(OutputStream output) throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [Patch] Fix commons-io test code
Posted by Stephen Colebourne <sc...@btopenworld.com>.
Raised and fixed as http://issues.apache.org/jira/browse/IO-96 (eventually!)
thanks
Stephen
Anthony Green wrote:
> This support routine from the commons-io project test code assumed that
> FileReader.read(byte[]) would always read the entire file. There's no
> such guarantee, and some tests were failing on GNU Classpath based VMs
> because of this.
>
> Thanks,
>
> AG
>
>
>
> --- src/test/org/apache/commons/io/testtools/FileBasedTestCase.java~ 2006-07-13 23:44:13.000000000 -0700
> +++ src/test/org/apache/commons/io/testtools/FileBasedTestCase.java 2006-07-13 23:44:20.000000000 -0700
> @@ -167,18 +171,22 @@
> throws IOException
> {
> Reader ir = new java.io.FileReader( file );
> - try {
> - char[] c1 = new char[ c0.length ];
> - int numRead = ir.read( c1 );
> - assertTrue( "Different number of bytes", numRead == c0.length );
> - for( int i = 0;
> - i < numRead;
> - assertTrue( "Byte " + i + " differs (" + c0[ i ] + " != " + c1[ i ] + ")",
> - c0[ i ] == c1[ i ] ), i++
> - );
> - } finally {
> - ir.close();
> - }
> + int count = 0, numRead = 0;
> + char[] c1 = new char[ c0.length ];
> + try {
> + while (count < c0.length)
> + {
> + numRead = ir.read( c1, count, c0.length);
> + for( int i = count;
> + i < count+numRead;
> + assertTrue( "Byte " + i + " differs (" + c0[ i ] + " != " + c1[ i ] + ")",
> + c0[ i ] == c1[ i ] ), i++
> + );
> + count += numRead;
> + }
> + } finally {
> + ir.close();
> + }
> }
>
> protected void checkWrite(OutputStream output) throws Exception {
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org