decoding utf8

T

timnels

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.
 
O

Oliver Wong

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
 
R

Roedy Green

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.
 
J

jan V

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...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top