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

Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified
Accepted Solution

Doubt regarding UTF-8 encoding!!


I m developing an application which supports multilanguage. Whenever I send the request to the server for french text I get a string consisting of french characters like (ex : L'erreur dans réagit réciproquement avec le service Blackberry Natal. ) . So assist those characters i have encoded the string that is received from the server to support utf -8 encoding using the below code 

private String readResponseAsString(InputStream strInput)
			throws IOException {
		byte[] data = new byte[256];
		int length = 0;
		StringBuffer strRawData = new StringBuffer();
		while (-1 != (length = strInput.read(data))) {
			strRawData.append(new String(data, 0, length,
					"UTF-8"));// Character encoding
		String strResponse = strRawData.toString();
		return strResponse;

 which is called when the response is received from the http connection as input stream like below:

// Response in the form a Input Stream
				oInputStream = oHttpConnection.openInputStream();
				// Response in the form of a String
				strResponse = readResponseAsString(oInputStream);

 Now the prob is some times french characters like(ex: é) are coneverted ot "?" despite encoding the response string to utf-8... And more over it happens only for a very  few characters and only for a very few times..  


Am I doing some thing wrong???

Posts: 17,022
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Doubt regarding UTF-8 encoding!!

i would suggest to read the data in first, using http://www.blackberry.com/developers/docs/7.1.0api/net/rim/device/api/io/IOUtilities.html#streamToBy...
you can then create a string with utf-8 from the byte array.
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
Posts: 174
Registered: ‎01-25-2011
My Device: Not Specified

Re: Doubt regarding UTF-8 encoding!!

Thanks for the reply.. prob solved!!