java: speed up reading foreign characters

Posted by Yang on Stack Overflow See other posts from Stack Overflow or by Yang
Published on 2010-04-09T21:16:25Z Indexed on 2010/04/09 21:33 UTC
Read the original article Hit count: 268

Filed under:
|

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();

© Stack Overflow or respective owner

Related posts about java

Related posts about inputstream