Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timob 9205-2_0_X: use CharsetDecoder to decode data. #2263

Merged
merged 4 commits into from
May 24, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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