Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

GZIPInputStream Problem

Hello Everyone,

I am facing a problem while passing gzipped data using GZIPInputStream,

if i am receiving character aphostrophy(') then i m getting correct data but if string contains  " ` " character ex. "shawa`s"

then its do unzipp like

Shawâ\u0080\u0099s

so any one know the character set that GZIPInputStream can not pass?

Thanks in Advance.

 

Lathiya Himanshu
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: GZIPInputStream Problem

Wait, what is happening? You use GZIP to compress "shawa`s" and when you uncompress it on BlackBerry using GZIPInputStream you get "Shawâ\u0080\u0099s" is that correct?

 

Two thoughts occur, one is that either what you are using to compress the text is messing up/written data is getting messed up/something along those lines or #2 that the encoding is different, Windows uses Unicode, Mac OS-X: UTF8, Linux varies but is moving (or at) UTF8. BlackBerry is ISO-8859-1 which shouldn't be a problem, I took your output text and converted it to "ISO-8859-1", then to UTF8 and got "Shaw’s", it's closer to what you wanted but missing a letter.

 

Hopefully that helps but I can't figure out why it might be doing that.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: GZIPInputStream Problem

Hi, rcmaniac

thanks for reply, you mean  that there are no any "Barred characters" for GZINputStream but there is some problem during zip or unzip... i wil check it.

 

Lathiya Himanshu
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIPInputStream Problem

[ Edited ]

I can assure you there are no barred characters for GZIP. 

 

However it expects to process bytes, not text. rcmaniac25's point is there is usually some conversion between bytes and text.  For example UTF-8 is one conversion code that can be used to convert a String on a BlackBerry to a sequence of bytes.  If you use one "text to bytes" conversion at one end and a different one at the other, you can get issues such as the one that you see.  Normal characters are fine, but the special ones get converted differently.  So you need to find out which conversion is being used at the other end, and make sure you use the same one at the BlackBerry end.   

Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: GZIPInputStream Problem

i am using the following code for streamOperation

 

byte[] b = IOUtilities.streamToBytes(inputStream);
b1 = new ByteArrayInputStream(b);

 

gzis = new GZIPInputStream(b1);
byte[] bdata = IOUtilities.streamToBytes(gzis);
data1 = new String(bdata);

 

is there any problem in this code?

i am using byte[]b  to find length of bytes for Processbar.

Lathiya Himanshu
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIPInputStream Problem

The issue here is not specifically what code you use at the BlackBerry end, or the Server end.  The issue is that the code at both ends matches, specifically when it converts the text data to byte data. 

 

In this case, you are creating the String using the default code set which I understand to be ISO-8859.  You need to check that the other end is using that same code set when it converts the text data to bytes, before it supplies it to GZIP for compression.

 

Is that clear?

 

Regarding this specific code, it will work as far as I can see, but I think the use of byte [] b does not help your progress bar much.  It will allow you distinguish between receiving the data and unpacking the data, but I would suggest that doing them in the same operation would actually result in a faster process for your users.  But this is a diversion, changing this will not effect your problem with rogue characters. 

Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: GZIPInputStream Problem

I tried the code for String Encoding

like

String str=new String(byteData,"UTF-8");

but its giving me the following Error.So any other way for Encoding?

"UnsupportingEncodingException:IOException in UniversalReader#byte ToCharArray()! Transcoder:awbfAn"

 

Thanks,

 

Lathiya Himanshu
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIPInputStream Problem

Is this on the BlackBerry?  UTF-8 is a supported encoding (I use it all the time) so this surprises me. 

Trusted Contributor
Posts: 227
Registered: ‎12-16-2009
My Device: 9530,8900,9000
My Carrier: Airtel,Docomo

Re: GZIPInputStream Problem

Yes,It it in Bberry... When i am running it in Debug mode it is not giving this error but if i run without debug mode its giving this error....

Lathiya Himanshu
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIPInputStream Problem

Sorry I misread the Exception.  What it is telling you is that the byte are NOT UTF-8.

 

What you need to do is to make sure the bytes that you receive on the BlackBerry are the same as the bytes you actually send from the server   So you need to track exactly what happens to the data. 

 

One way of doing this involves printing the raw bytes.  The easiest way to print them is to convert the bytes to hexadecimal, I believe there are a number of byte array to Hex String type routines on the forum, if not on the Web.

 

On the Server, print off the String you are sending, and, using a bytes-to-hex routine, the bytes that this String gets converted to before it is GZIPped.  On the BlackBerry, print off the bytes that you receive using a bytes-to-hex routine. 

 

You need to print off the raw bytes.  So you can't do:

String printString = new String(<bytes>);

because this converts the bytes to characters.  

 

Once you have done that, make sure they are the same.  I'm guessing that they will be.  So then you need to look at the Server and understand how it converts the Text to a sequence of bytes.  What mechanism it uses must be replicated on the BlackBerry. 

 

If it is not possible to print off the bytes sent on the Server, then you are doing to have to review the documentation to understand the format of the bytes sent. 

 

So at this time, focus your attention on understanding what the Server does with the text and what encoding it is using, rather than trying to change the BlackBerry.