B4J Question WINDOWS-1252 Character Encoding

potman100

Active Member
Licensed User
Longtime User
Hi

I have an app that I have written in B4A that basically download articles from Usenet, once download they need to be decoded using

B4X:
msg = BytesToString(buffer, 0, buffer.Length, "WINDOWS-1252")

This all works fine in B4A.

I have tried to use the same code on B4J and when running the ByteToString function if produces different chartacters.

I checked the bytes being supplied by the AStreams_NewData sub and both are the same data on B4A and B4J. but when I run the BytesToString function the output is different


This is from B4A

=ybegin line=128 size=416 name=index.zip
zu-=n>***2*-²Ønåø¨Ó***/+**3*œ*s˜Ž¢Xž¢ž}n‡*Î****2*xŠ£ŽŠ“:‹ŠŠz‹ª*1JŽ,]ƒ?ª®,º÷ò4 µ,3CӁˆ´”X<3¥\-θ³K¯«/VWëÉ{HmY-2nÆ;LX®×=n
ít0K>›oJE*~7*1/½}/½}/½}·÷[5ìZ:° ‡iŽ†œÁP/»¬4øTD÷s/×ü=@²ºI™/›=}Æh¢ =@L‘“ÿ†&ZÇü*Î=@²5=nßDÄ„°hÔÇX‚÷¢=}}µn»îðc‘Çý3C*†+oØ
_Ȭ~¦ùEÿ}¦…s=}mÀtì§0C…œPeºâ=JS=}=}º¹@ÕpH‡åè9±$kD0nà^&opÝ+E‹¢Mþ©G·qYzu+,A5>***2*-²Ønåø¨Ó***/+**3*;*****+*J*à«****s˜Ž
¢Xž¢ž}n=n*Î***~/*1/½}zu/0****+*+*r***l+****
=yend size=416 crc32=7104947d

This is from B4J

=ybegin line=128 size=416 name=index.zip
zu-=n>***2*-²Ønåø¨Ó***/+**3*œ*s˜Ž�¢Xž¢ž}n‡*Î****2*xŠ£�ŽŠ“:‹ŠŠz‹ª*1J�Ž,]ƒ?ª®,º÷ò4 µ,3CÓ�ˆ´”X<3¥\-θ³K¯«/VWëÉ{HmY-2nÆ;LX®�×=n
ít0K>›oJE*~7*1/½�}/½�}/½�}·÷[5ìZ:° ‡iŽ†œÁP/»¬4øTD÷s/×ü=@²ºI™/›=}Æh¢ =@L‘“ÿ†&ZÇü*Î=@²5=nßDÄ„°hÔÇX‚÷¢=}}µn»îðc‘Çý3C*†+oØ
_Ȭ~¦ùEÿ}¦…s=}mÀtì§0C…œPeºâ=JS=}=}º¹@ÕpH‡åè9±�$kD0nà^&opÝ+E‹¢Mþ©G·qYzu+,A5>***2*-²Ønåø¨Ó***/+**3*;*****+*J*à«****s˜Ž�
¢Xž¢ž}n=n*Î***~/*1/½�}zu/0****+*+*r***l+****
=yend size=416 crc32=7104947d

The problem is the � character means it is unknown, the final output from both the above should be a zip file, the B4A one is complete and works fine, where as the B4J one is corrupt.

I've tried all sorts to fix this, but have not been able to find a fix.

Anybody any idea's ??

Regards

Potman
 

potman100

Active Member
Licensed User
Longtime User
Hi Erel

Just the way I've always done it in VB6, and never had an issue !

Anyway I started to have a play with just using the bytes and not converting and have now managed to get it working ok.

Thanks for pushing me in the right direction.

Just 1 other thing, do you know of anyway to implement rar functionality in B4J ?

Regards

Potman
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
"random" bytes cannot be treated as string. Not all possible values are valid unicode characters.

Just 1 other thing, do you know of anyway to implement rar functionality in B4J ?
Note that it is better to start a new thread for a new question. Currently there isn't any library that opens rar files. You can use jShell to run a program that will extract the rar file for you.
 
Upvote 0
Top