You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Vasily Zakharov (JIRA)" <ji...@apache.org> on 2007/04/18 21:37:15 UTC

[jira] Created: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

[classlib][luni] Reader and Writer convert characters incorrectly
-----------------------------------------------------------------

                 Key: HARMONY-3702
                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Vasily Zakharov


java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.

The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.

public class ReaderTest {
    public static void main(String args[]) throws Exception {
        char[] buffer = new char[0x100000];
        java.io.Reader reader = new java.io.FileReader("test.dat");
        int length = reader.read(buffer, 0, buffer.length);

        for (int i = 0; i < length; i++) {
            System.out.println((int) buffer[i]);
        }
    }
}

public class WriterTest {
    public static void main(String args[]) throws Exception {
        byte[] buffer = new byte[0x100000];
        java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
        int length = iStream.read(buffer, 0, buffer.length);
        char[] charBuffer = new char[length];

        for (int i = 0; i < length; i++) {
            charBuffer[i] = (char) buffer[i];
        }
        java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
        writer.write(charBuffer, 0, length);
        writer.close();
    }
}

In both cases, output files on RI and on Harmony are different:

$ RI/bin/java ReaderTest > reader.ri
$ HY/bin/java ReaderTest > reader.hy
$ diff --binary -q reader.ri reader.hy
Files reader.ri and reader.hy differ

$ RI/bin/java WriterTest > writer.ri
$ HY/bin/java WriterTest > writer.hy
$ diff --binary -q writer.ri writer.hy
Files writer.ri and writer.hy differ

My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.

The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.


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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12514520 ] 

Vasily Zakharov commented on HARMONY-3702:
------------------------------------------

I've checked the issue on the current build. The results are as follows:

WriterTest works identically on RI, Harmony/IBMVM and Harmony/DRLVM.

ReaderTest work differently on RI, Harmony/IBMVM and Harmony/DRLVM - the outputs are similar, but all three are different.

So, though HARMONY-3307 is now resolved, the problem still exists.


> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490241 ] 

Vasily Zakharov commented on HARMONY-3702:
------------------------------------------

I'm not sure if this is a non-bug difference. Probably we should have the same default encoding as RI, for compatibility.

Probably this should be discussed in the mailing list.


> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Ruth Cao (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12489920 ] 

Ruth Cao commented on HARMONY-3702:
-----------------------------------

Hello Vasily,
I've tried some test data but cannot reproduce this issue. May you pls upload the "test.dat" file you use so that I can investigate it further? Thanks a lot.

> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12489877 ] 

Vasily Zakharov commented on HARMONY-3702:
------------------------------------------

This issue was discovered while investigating HARMONY-3703.


> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12489990 ] 

Vasily Zakharov commented on HARMONY-3702:
------------------------------------------

Sorry, Ruth, I forgot to attach the file. Here it goes.

Thank you!


> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Updated: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Vasily Zakharov updated HARMONY-3702:
-------------------------------------

    Attachment: test.dat

> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Vasily Zakharov (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490348 ] 

Vasily Zakharov commented on HARMONY-3702:
------------------------------------------

Here's the discussion of this issue on the mailing list:
http://thread.gmane.org/gmane.comp.java.harmony.devel/26077


> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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


[jira] Commented: (HARMONY-3702) [classlib][luni] Reader and Writer convert characters incorrectly

Posted by "Ruth Cao (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/HARMONY-3702?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12490216 ] 

Ruth Cao commented on HARMONY-3702:
-----------------------------------

Vasily, thank you for your test file. I've looked into this bug and found it is due to the different default encoding between RI, IBMVME and DRLVM.

More information can be found at HARMONY-3307: http://issues.apache.org/jira/browse/HARMONY-3307#action_12488642

Thus, IMHO, it might be a non-bug difference for Harmony and RI. How do you think?

> [classlib][luni] Reader and Writer convert characters incorrectly
> -----------------------------------------------------------------
>
>                 Key: HARMONY-3702
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3702
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Vasily Zakharov
>         Attachments: test.dat
>
>
> java.io.Reader converts bytes to characters differently than RI does. Also, java.io.Writer converts characters to bytes differently than RI does.
> The attached test.dat file contains random test data and must be placed to the current directory. ReaderTest below reads that file with FileReader and then dumps it to standard output by converting each character to int. WriterTest reads the test.dat file with FileInputStream, converts each byte to character by casting and then dumps the resulting characters to standard output by OutputStreamWriter.
> public class ReaderTest {
>     public static void main(String args[]) throws Exception {
>         char[] buffer = new char[0x100000];
>         java.io.Reader reader = new java.io.FileReader("test.dat");
>         int length = reader.read(buffer, 0, buffer.length);
>         for (int i = 0; i < length; i++) {
>             System.out.println((int) buffer[i]);
>         }
>     }
> }
> public class WriterTest {
>     public static void main(String args[]) throws Exception {
>         byte[] buffer = new byte[0x100000];
>         java.io.InputStream iStream = new java.io.FileInputStream("test.dat");
>         int length = iStream.read(buffer, 0, buffer.length);
>         char[] charBuffer = new char[length];
>         for (int i = 0; i < length; i++) {
>             charBuffer[i] = (char) buffer[i];
>         }
>         java.io.Writer writer = new java.io.OutputStreamWriter(System.out);
>         writer.write(charBuffer, 0, length);
>         writer.close();
>     }
> }
> In both cases, output files on RI and on Harmony are different:
> $ RI/bin/java ReaderTest > reader.ri
> $ HY/bin/java ReaderTest > reader.hy
> $ diff --binary -q reader.ri reader.hy
> Files reader.ri and reader.hy differ
> $ RI/bin/java WriterTest > writer.ri
> $ HY/bin/java WriterTest > writer.hy
> $ diff --binary -q writer.ri writer.hy
> Files writer.ri and writer.hy differ
> My investigations show that the problem is in Reader/Writer, not in InputStream/OutputStream. Also, I've tried other implementations of Reader/Writer and they share the same problem.
> The problem was discovered on Windows XP/IA-32 but probably affects other platforms too.

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