Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 71163 invoked from network); 18 Apr 2006 08:26:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 18 Apr 2006 08:26:18 -0000 Received: (qmail 41088 invoked by uid 500); 18 Apr 2006 08:26:17 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 41055 invoked by uid 500); 18 Apr 2006 08:26:17 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 41044 invoked by uid 99); 18 Apr 2006 08:26:17 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Apr 2006 01:26:17 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [209.237.227.198] (HELO brutus.apache.org) (209.237.227.198) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Apr 2006 01:26:16 -0700 Received: from brutus (localhost.localdomain [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id E146A7142CA for ; Tue, 18 Apr 2006 08:25:17 +0000 (GMT) Message-ID: <4932979.1145348717863.JavaMail.jira@brutus> Date: Tue, 18 Apr 2006 08:25:17 +0000 (GMT+00:00) From: "Mikhail Loenko (JIRA)" To: harmony-commits@incubator.apache.org Subject: [jira] Commented: (HARMONY-166) method read() in InputStreamReader failed to read one character MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/HARMONY-166?page=comments#action_12374874 ] Mikhail Loenko commented on HARMONY-166: ---------------------------------------- Cannot reproduce this in revision 394878 > method read() in InputStreamReader failed to read one character > --------------------------------------------------------------- > > Key: HARMONY-166 > URL: http://issues.apache.org/jira/browse/HARMONY-166 > Project: Harmony > Type: Bug > Components: Classlib > Reporter: Vladimir Strigun > Attachments: InputStreamReader.patch.txt, InputStreamReaderTest.java > > I've started to play with harmony-57 contribution and found bug in InputStreamReader class. Method read() should read a single character from input stream but it works incorrectly for 2 bytes-per-char charsets. Example below shows that it failed to read one character in UTF-16 charset. Sorry for so ugly test, it's just a part of InputStreamReaderTest from Harmony-57 contribution. > import java.io.*; > import junit.framework.TestCase; > public class InputStreamReaderTest extends TestCase { > public static void main(String[] args) { > junit.textui.TestRunner.run(InputStreamReaderTest.class); > } > public void test_ISR_read() throws Exception { > InputStream in; > InputStreamReader reader; > try { > in = new LimitedByteArrayInputStream(0); > reader = new InputStreamReader(in, "UTF-16BE"); > int xx = reader.read(); > assertTrue("Incorrect byte UTF-16BE", xx == '\u6172'); > } catch (UnsupportedEncodingException e) { > // Can't test without the converter > System.out.println(e); > } catch (IOException e) { > e.printStackTrace(); > fail("UTF-16BE unexpected 1: " + e); > } > try { > in = new LimitedByteArrayInputStream(0); > reader = new InputStreamReader(in, "UTF-16LE"); > int xx = reader.read(); > assertTrue("Incorrect byte UTF-16BE", xx == '\u7261'); > } catch (UnsupportedEncodingException e) { > // Can't test without the converter > } catch (IOException e) { > fail("UTF-16BE unexpected 2: " + e); > } > try { > in = new LimitedByteArrayInputStream(1); > reader = new InputStreamReader(in, "UTF-16"); > assertTrue("Incorrect byte UTF-16BE", reader.read() == '\u7261'); > } catch (UnsupportedEncodingException e) { > // Can't test without the converter > } catch (IOException e) { > fail("UTF-16BE unexpected 3: " + e); > } > try { > in = new LimitedByteArrayInputStream(2); > reader = new InputStreamReader(in, "ISO2022JP"); > int ch = reader.read(); > assertTrue("Incorrect byte ISO2022JP 1: " + ch, ch == '\u4e5d'); > ch = reader.read(); > assertTrue("Incorrect byte ISO2022JP 2: " + ch, ch == '\u7b2c'); > } catch (UnsupportedEncodingException e) { > // Can't test without the converter > System.out.println(e); > } catch (IOException e) { > fail("ISO2022JP unexpected: " + e); > } > } > static class LimitedByteArrayInputStream extends ByteArrayInputStream { > // A ByteArrayInputStream that only returns a single byte per read > byte[] bytes; > int count; > public LimitedByteArrayInputStream(int type) { > super(new byte[0]); > switch (type) { > case 0: > bytes = new byte[] { 0x61, 0x72 }; > break; > case 1: > bytes = new byte[] { (byte) 0xff, (byte) 0xfe, 0x61, 0x72 }; > break; > case 2: > bytes = new byte[] { '\u001b', '$', 'B', '6', 'e', 'B', 'h', > '\u001b', '(', 'B' }; > break; > } > count = bytes.length; > } > public int read() { > if (count == 0) > return -1; > count--; > return bytes[bytes.length - count]; > } > public int read(byte[] buffer, int offset, int length) { > if (count == 0) > return -1; > if (length == 0) > return 0; > buffer[offset] = bytes[bytes.length - count]; > count--; > return 1; > } > public int available() { > return count; > } > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira