harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mikhail Markov (JIRA)" <j...@apache.org>
Subject [jira] Updated: (HARMONY-3854) [classlib][luni] InputStreamReader.read(char[] buffer) doesn't fill in all the buffer when input is still available
Date Sat, 09 Jun 2007 15:12:26 GMT

     [ https://issues.apache.org/jira/browse/HARMONY-3854?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Mikhail Markov updated HARMONY-3854:
------------------------------------

    Attachment: H-3854_upd.patch

Here is the patch enabling the original idea of filling the output CharBuffer with chunks
and not allocating the internal buffer equal to the size of data available in input stream.
The mentioned 3 tests passed with it but unfortunately it could not be immediately applied
due to some problems with UTF-8 decoding (see HARMONY-4117) but when 4117 is fixed this patch
could be applied as well.

Could someone please review the patch or improve it? Thanks!


> [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
>            Assignee: Paulex Yang
>         Attachments: H-3854_upd.patch, InputStreamReader_3854.patch, readTest.zip, readTest2.zip,
readTest3.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