Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > java multibyte char array

Reply
Thread Tools

java multibyte char array

 
 
kaith
Guest
Posts: n/a
 
      08-21-2003
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?
 
Reply With Quote
 
 
 
 
Shripathi Kamath
Guest
Posts: n/a
 
      08-21-2003

"kaith" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) m...
> 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


 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-21-2003
On 20 Aug 2003 17:21:27 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
Jon A. Cruz
Guest
Posts: n/a
 
      08-21-2003
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How should I handle the multibyte char set string in C++? Dancefire C++ 10 05-05-2007 09:49 PM
length of 2D Array >> char **myString= (char **) malloc (sizeof (char *)); davidb C++ 0 09-01-2006 03:22 PM
(const char *cp) and (char *p) are consistent type, (const char **cpp) and (char **pp) are not consistent lovecreatesbeauty C Programming 1 05-09-2006 08:01 AM
Problem- strcat with char and char indexed from char array aldonnelley@gmail.com C++ 3 04-20-2006 07:32 AM
/usr/bin/ld: ../../dist/lib/libjsdombase_s.a(BlockGrouper.o)(.text+0x98): unresolvable relocation against symbol `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostre silverburgh.meryl@gmail.com C++ 3 03-09-2006 12:14 AM



Advertisments