Difference in int cast to char between Windows and redhat linux 9 under JDK 1.4.2_06

Discussion in 'Java' started by Private, Dec 10, 2004.

  1. Private

    Private Guest

    Difference in int cast to char between Windows and redhat linux 9 under JDK
    1.4.2_06

    With regards to the following; how can I control the charset used for the
    cast ? The desired outcome would be for 0x80 to cast to '\u0080'. At
    the least I need to be able to run consistently across the two platforms.

    Thanks to all for any help on this.

    <java code CharTester fragment>

    FileInputStream fis=new FileInputStream(args[0]);

    for (int i=fis.read();i>-1;i=fis.read())
    System.out.print((char)i);

    System.out.flush();
    fis.close();

    </fragment>

    <test run under linux>

    # hexdump -C < print.doc
    00000000 7e 7f 80 81 fc fd ff |~......|
    00000007

    # java com.asl.hacks.CharTester print.doc
    # java com.asl.hacks.CharTester print.doc | hexdump -C
    00000000 7e 7f c2 80 c2 81 c3 bc c3 bd c3 bf |~...........|
    0000000c

    </test>

    under windows the same command produces

    7e 7f 3f 3f fc fd ff
    Private, Dec 10, 2004
    #1
    1. Advertising

  2. Private

    Alex Kizub Guest

    Re: Difference in int cast to char between Windows and redhat linux 9under JDK 1.4.2_06

    > under windows the same command produces
    >
    > 7e 7f 3f 3f fc fd ff


    You use none ASCII characters. Read more about InputStream and Readers and what
    is the difference betwen them.
    Also check what is the locale on your Windows and Linux systems. I bet they are
    different.

    Alex Kizub.
    Alex Kizub, Dec 11, 2004
    #2
    1. Advertising

  3. Re: Difference in int cast to char between Windows and redhat linux9 under JDK 1.4.2_06

    Private wrote:
    > Difference in int cast to char between Windows and redhat linux 9 under JDK
    > 1.4.2_06


    No.

    > With regards to the following; how can I control the charset used for the
    > cast ?


    There is no charset involved in such a cast, both are integer types.

    > The desired outcome would be for 0x80 to cast to '\u0080'.


    And that is what will happen. Always.

    > <java code CharTester fragment>
    >
    > FileInputStream fis=new FileInputStream(args[0]);
    >
    > for (int i=fis.read();i>-1;i=fis.read())
    > System.out.print((char)i);


    Ah, well this is a different thing. You are reading the byte values and
    interpreting them as unicode code points. That's equivalent to using
    the ISO-8859-1 charset.

    But the platform dependence is not in the casting from int, it's in the
    call of print(), which uses the platform default encoding to convert the
    character back to bytes, which then appear on the program's standard
    output.

    What is the program supposed to do, anyway?
    Michael Borgwardt, Dec 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. U. George
    Replies:
    4
    Views:
    835
    U. George
    Aug 11, 2005
  2. Schnoffos
    Replies:
    2
    Views:
    1,208
    Martien Verbruggen
    Jun 27, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,629
    Old Wolf
    Jan 20, 2004
  4. Ulf Meinhardt
    Replies:
    0
    Views:
    6,417
    Ulf Meinhardt
    Aug 10, 2006
  5. arun
    Replies:
    8
    Views:
    452
    Dave Thompson
    Jul 31, 2006
Loading...

Share This Page