One other little flaw there -- possibly serious -- is not specifying the 
encoding in the new InputStreamReader(stream, encoding) call.

Generally, you should use UTF-8 if you have a choice -- and you should use 
what was supplied by the server, in any event. If you're writing the server, 
make it UTF-8 on that end.

And you should use StringBuilder rather than  StringBuffer - a more 
efficient replacement. StringBuffer has synchronized methods, which are 
wasteful when you're using it from a single thread, as here, and in the vast 
majority of cases.

And rather than using BufferedReader and readLine, it is more efficient to 
allocate a single char[] array, and use that in a loop:

HttpEntity entity = response.getEntity();
Reader in = new InputStreamReader(entity.getContent(), 
entity.getContentEncoding());
try {
    StringBuilder sb = new StringBuilder();
    char[] buf = new char[1024];
    int count = 0;
    while ((count = in.read(buf)) >= 0) {
        sb.append(buf, 0, count);
    }
   return sb.toString();
} finally {
  in.close();
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to