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
Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry
Accepted Solution

GZIP- problem for turkish language

Hi All,
I am using gzip for content-encoding and accept-encoding in properties. For turkish language gzip is not working fine it shows like Cem Akku��, H�¼seyin ��al�±��kan. how to achieve properly.

 

Thanks...

Developer
Posts: 16,687
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: GZIP- problem for turkish language

gzip is not an encoding. use proper unicode.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: GZIP- problem for turkish language

Hi,

 

hc.setRequestMethod(HttpConnection.POST);
hc.setRequestProperty("Content-Type", "application/x-gzip");
hc.setRequestProperty("Content-Encoding", "gzip");
hc.setRequestProperty("Accept-Encoding", "gzip");
hc.setRequestProperty("Locale", WebServiceConstants.Locale);

 

this is my request with my url, how to send the unicode with this request...

 

 

Developer
Posts: 19,629
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIP- problem for Turkish language

The problem is most likely the input to gzip.  You gzip a stream of bytes.  When you supply the bytes to gzip, from a String, don't just do this

 

bytes = string.getBytes();

 

do this

 

bytes = string.getBytes("UTF-8");

Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: GZIP- problem for Turkish language

Hi peter,
am using the below code but again the trukish language are not displays like this only Akku��, H�¼seyin ��al�±��kan..

public void zipRequest(OutputStream io, String data) throws Exception{
try{
GZIPOutputStream gz = new GZIPOutputStream(io);
byte[] bytes = data.getBytes("UTF-8");
gz.write(bytes, 0, bytes.length);
gz.close();
}
catch(Exception ex){
Dialog.alert("zipRequest :"+ex.getMessage());
}
Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: GZIP- problem for Turkish language

Sorry this is my unzip response,
public String unzipResponse(InputStream io) throws Exception {
StringBuffer sb=new StringBuffer();
try{
GZIPInputStream gz = new GZIPInputStream(io);
int c = 0;
while ((c = gz.read()) != -1) {
sb.append((char) c);
}
gz.close();
}
catch(Exception ex){
Dialog.alert("unzipResponse :"+ex.getMessage());
}
return sb.toString();
}
Developer
Posts: 19,629
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIP- problem for Turkish language

I am not clear on where you are seeing this problem.

 

As I understand it, you are doing the following:

 

a) You have some data, in a String, on the BlackBerry

b) You convert that data to bytes

c) You add these bits to a GZIP stream

d) You send this GZIP stream to your Server

e) Your Server decompresses the GZIP stream

f) the Server converts the bytes to characters

 

If this is not the processing that is happening, can you please describe what is going on, in this level of detail.

 

Once we have the process that your data is going through completely described, can you then tell us which point you see this 'corruption'. 

 

I have just thought of another option - this could be a font issue. 

 

What I recommend you do to see if this is a font issue, is to write some debugging code that converts the String to a char array, and then dumps out the values of each characters.  Check that the Unicode character is in fact what you expect it to be.  If it is, but the display is showing a ? or some other symbol, then you have a font issue  because the font does not have the required characters. 

 

I think the font used debug window in Eclipse might not include Turkish characters, so it might display characters it does not recognize as "?". 

Developer
Posts: 19,629
Registered: ‎07-14-2008
My Device: Not Specified

Re: GZIP- problem for Turkish language

Just seen your second message. 

 

I suspect your problem is in unzipResponse - try this code instead.  By the way, I have just written this, not compiled or tested, hopefully you get the idea and can correct any errors you find.

 

public String unzipResponse(InputStream io) throws Exception {
String returnString = "";
try{
GZIPInputStream gz = new GZIPInputStream(io);
byte [] bytes = IOUtilities.streamToBytes(gz);
returnString = new String(bytes,"UTF-8");
}
catch(Exception ex){
Dialog.alert("unzipResponse :"+ex.getMessage());
}
return returnString;
}

Developer
Posts: 16,687
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: GZIP- problem for Turkish language

just don't use dialog.alert without an invokelater as your processing does not run on the event thread (i hope).
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Regular Contributor
Posts: 87
Registered: ‎04-30-2013
My Device: 9220
My Carrier: Blackberry

Re: GZIP- problem for Turkish language

Thanks pieter.. Its working fine..