harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Elena Sayapina (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-3854) [classlib][luni] InputStreamReader.read(char[] buffer) doesn't fill in all the buffer when input is still available
Date Mon, 14 May 2007 09:41:16 GMT
[classlib][luni] InputStreamReader.read(char[] buffer) doesn't fill in all the buffer when
input is still available
-------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-3854
                 URL: https://issues.apache.org/jira/browse/HARMONY-3854
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Elena Sayapina
         Attachments: readTest.zip

Method read of InputStreamReader works incorrectly in some cases.

If call method read(char[] buffer) with the non-tiny buffer more than two times it reads chars
incorrectly, 
i.e. doesn't fill in all the buffer when some input is still available.

Please, consider the following piece of code (note that data.txt contains about 14000 chars):

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class readTest {

	public static void main(String[] args) throws IOException {
		
		String filename = new String("data.txt");
		System.out.println("Data file length: " + new File(filename).length());
		InputStream stream = new FileInputStream(new File(filename));
		InputStreamReader reader = new InputStreamReader(stream);
		
		int read = 0;
		char[] buffer = new char[4];
		System.out.println("Char buffer capacity: " + buffer.length);
		try {
			read = reader.read(buffer);
		} catch (Exception e) {
		    e.printStackTrace();
		    System.out.println("TEST FAILED: unexpected" + e);
		}
		System.out.println("Number of chars read: " + read);

		read = 0;
		buffer = new char[9000];
		System.out.println("Char buffer capacity: " + buffer.length);
		try {
			read = reader.read(buffer);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("TEST FAILED: unexpected" + e);
		}
		System.out.println("Number of chars read: " + read);
	    
	    System.out.println("buffer[8999]: " + buffer[8999]);
	    System.out.println("buffer[8998]: " + buffer[8998]);
	    System.out.println("buffer[8189]: " + buffer[8189]);
	    System.out.println("buffer[8188]: " + buffer[8188]);
	    System.out.println("buffer[8187]: " + buffer[8187]);
	    
	    if (read == buffer.length) System.out.println("TEST PASSED");
	    else System.out.println("TEST FAILED");
	}
}


Output on Harmony-r537585:

Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors,
as applicable.
java version "1.5.0"
pre-alpha : not complete or compatible
svn = r537585, (May 13 2007), Windows/ia32/msvc 1310, debug build
http://incubator.apache.org/harmony

Data file length: 14000
Char buffer capacity: 4
Number of chars read: 4
Char buffer capacity: 9000
Number of chars read: 8188
buffer[8999]:
buffer[8998]:
buffer[8189]:
buffer[8188]:
buffer[8187]: t
TEST FAILED

Output on HotSpot:

java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)

Data file length: 14000
Char buffer capacity: 4
Number of chars read: 4
Char buffer capacity: 9000
Number of chars read: 9000
buffer[8999]: t
buffer[8998]: s
buffer[8189]: e
buffer[8188]: T
buffer[8187]: t
TEST PASSED

NOTE that if remove first try..catch block with reader.read(buffer) then test passes,
or if reduce buffer size from 9000 to 8188 test also passes.

Please, use the data from attached readTest.zip to reproduce the failure.




-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message