java: speed up reading foreign characters
- by Yang
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();