decoding utf8  
Author Message
timnels





PostPosted: 2005-9-22 23:22:00 Top

java-programmer, decoding utf8 I've got a J2ME application that is doing a writeUTF() of a byte array
that I need to decode and store in a flat file (it's a jpeg) from my
perl socket application. I can't seem to find a way to have Perl
decode it into it's byte representation.

As a test I put a byte array of just control-A's on the wire using
writeUTF. The length of the scalar I get in Perl is exactly twice (128)
as I sent (64). I've tried doing: $decoded =
Encode::decode_utf8($netbuf) and it doesn't convert the data at all.
Obviously, I must be missing how Perl handles a scalar that contains
UTF-8 data.

Can someone point me in a direction? Thanks.

 
Oliver Wong





PostPosted: 2005-9-23 0:43:00 Top

java-programmer >> decoding utf8
<email***@***.com> wrote in message
news:email***@***.com...
> I've got a J2ME application that is doing a writeUTF() of a byte array
> that I need to decode and store in a flat file (it's a jpeg) from my
> perl socket application.

It sounds like there are so many places where something can go wrong in
this pipeline.

> I can't seem to find a way to have Perl
> decode it into it's byte representation.
>
> As a test I put a byte array of just control-A's on the wire using
> writeUTF. The length of the scalar I get in Perl is exactly twice (128)
> as I sent (64).

control-As being the character with ASCII code 0x01, correct? As far as I
know, UTF-8 encodes that character using one byte. Since the size is being
doubled, and "writeUTF" doesn't imply "Write in UTF-8 format", could it be
that you're actually writing in UTF-16 format? UTF-16 encodes the 0x01
character using two bytes.

> I've tried doing: $decoded =
> Encode::decode_utf8($netbuf) and it doesn't convert the data at all.

Well, this doesn't look like a Java method call. Is it a Perl method
call? Have you tried posting on a Perl newsgroup?

> Obviously, I must be missing how Perl handles a scalar that contains
> UTF-8 data.
>
> Can someone point me in a direction? Thanks.

Have you considered NOT converting your JPEG data to UTF-8 and back?

- Oliver


 
Roedy Green





PostPosted: 2005-9-23 5:35:00 Top

java-programmer >> decoding utf8 On 22 Sep 2005 08:21:51 -0700, email***@***.com wrote or quoted :

>I've got a J2ME application that is doing a writeUTF() of a byte array
>that I need to decode and store in a flat file (it's a jpeg) from my
>perl socket application. I can't seem to find a way to have Perl
>decode it into it's byte representation.

You have a Perl question, not a Java question. Try asking elsewhere.
One brute force option is to write a char[] instead as a list of 16
bit chars.

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.
 
 
jan V





PostPosted: 2005-9-29 21:44:00 Top

java-programmer >> decoding utf8 > Obviously, I must be missing how Perl handles a scalar that contains
> UTF-8 data.
>
> Can someone point me in a direction? Thanks.

comp.lang.perl might be one direction...