views:

61

answers:

1

My current code needs to read foreign characters from the web, currently my solution works but it is very slow, since it read char by char using InputStreamReader. Is there anyway to speed it up and also get the job done?

// Pull content stream from response
        HttpEntity entity = response.getEntity();
        InputStream inputStream = entity.getContent();

        StringBuilder contents = new StringBuilder();
        int ch;
        InputStreamReader isr = new InputStreamReader(inputStream, "gb2312");
          // FileInputStream file = new InputStream(is);
         while( (ch = isr.read()) != -1)
             contents.append((char)ch);
         String encode = isr.getEncoding();

         return contents.toString();
+6  A: 

Wrap your InputStreamReader with a BufferedReader

for the efficient reading of characters, arrays, and lines.

InputStreamReader isr = new InputStreamReader(inputStream, "gb2312");
Reader reader = new BufferedReader(isr);
Brabster