java multibyte char array

Discussion in 'Java' started by kaith, Aug 21, 2003.

  1. kaith

    kaith Guest

    I have a java GUI talking to C++ program at backend. The C++ program
    writes to a
    InputStreamReader that is then read by the java program. I do the
    following:

    InputStreamReader test1;
    char[] buffer = new char[128];
    ..
    ..
    test1.read(buffer);

    Then I use buffer.length to do some processing. The problem is in
    english everything works fine but it doesn't for multibyte characters
    (japanes, chinese). buffer.length is a wierd number in that case. What
    should I do?
    kaith, Aug 21, 2003
    #1
    1. Advertising

  2. "kaith" <> wrote in message
    news:...
    > I have a java GUI talking to C++ program at backend. The C++ program
    > writes to a
    > InputStreamReader that is then read by the java program. I do the
    > following:
    >
    > InputStreamReader test1;
    > char[] buffer = new char[128];
    > .
    > .
    > test1.read(buffer);
    >
    > Then I use buffer.length to do some processing. The problem is in
    > english everything works fine but it doesn't for multibyte characters
    > (japanes, chinese). buffer.length is a wierd number in that case. What
    > should I do?


    Is buffer.length ever anything other 128?

    Also, if the C++ side writing stuff out in UNICODE or MBCS? If it is
    writing out in MBCS, clearly you have a mismatch in usage, because a char is
    a 16-bit UNICODE char.

    It would help someone help you better if you posted the actual code, and
    provided the actual values instead of simply characterizing the number as
    "wierd". It is not possible from your description to ascertain what is
    "wierd" about a number.

    --
    Shripathi Kamath
    NETAPHOR SOFTWARE INC.
    http://www.netaphor.com
    Shripathi Kamath, Aug 21, 2003
    #2
    1. Advertising

  3. kaith

    Roedy Green Guest

    On 20 Aug 2003 17:21:27 -0700, (kaith) wrote or
    quoted :

    >Then I use buffer.length to do some processing. The problem is in
    >english everything works fine but it doesn't for multibyte characters
    >(japanes, chinese). buffer.length is a wierd number in that case. What
    >should I do?


    For a start read http://mindprod.com/jgloss/encoding.html

    The come back and tell us what encoding you are creating and what
    encoding the C program is expecting.

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
    Roedy Green, Aug 21, 2003
    #3
  4. kaith

    Jon A. Cruz Guest

    kaith wrote:
    > I have a java GUI talking to C++ program at backend. The C++ program
    > writes to a
    > InputStreamReader that is then read by the java program. I do the
    > following:
    >
    > InputStreamReader test1;
    > char[] buffer = new char[128];


    Well, there's your problem.

    characters and bytes are two different things. In C/C++ bytes are most
    often used to store characters, but in Java it uses 16-bit unsigned
    Unicode 'char' types to do so.

    You need to intelligently convert those raw bytes into characters using
    the proper encoding.
    Jon A. Cruz, Aug 21, 2003
    #4
    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. lovecreatesbeauty
    Replies:
    1
    Views:
    1,034
    Ian Collins
    May 9, 2006
  2. Replies:
    3
    Views:
    730
  3. davidb
    Replies:
    0
    Views:
    759
    davidb
    Sep 1, 2006
  4. davidb
    Replies:
    6
    Views:
    1,544
    Default User
    Sep 1, 2006
  5. Dancefire
    Replies:
    10
    Views:
    1,118
Loading...

Share This Page