Skip to content

Commit

Permalink
Merge pull request #2263 from hieupham007/timob-9205-2_0_X
Browse files Browse the repository at this point in the history
Timob 9205-2_0_X:  use CharsetDecoder to decode data.
  • Loading branch information
vishalduggal committed May 24, 2012
2 parents cef0b9f + 49d6164 commit 35ecaef
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -550,18 +554,23 @@ public void sendError(String error)

public String getResponseText()
{

if (responseData != null && responseText == null) {
if (charset == null) {
charset = HTTP.UTF_8;
}

try {
responseText = new String(responseData.getBytes(), charset);
} catch (UnsupportedEncodingException e) {
Log.e(LCAT, "Unable to convert to String using charset: " + charset);
CharsetDecoder decoder = Charset.forName(charset).newDecoder();
ByteBuffer data = ByteBuffer.wrap(responseData.getBytes());
CharBuffer b = decoder.decode(data);
responseText = b.toString();
} catch (Exception e) {
Log.e(LCAT, "Unable to decode using charset: " + charset);
} catch (OutOfMemoryError e) {
Log.e(LCAT, "Unable to get response text: out of memory");
Log.e(LCAT, "Unable to get response text: out of memory");
}

}

return responseText;
Expand Down

0 comments on commit 35ecaef

Please sign in to comment.