HttpEntity multipart = builder.build();
httppost.setEntity(multipart);
long start = System.currentTimeMillis();
// 发送请求
response = httpclient.execute(httppost);
long end = System.currentTimeMillis();
System.out.println("查询upsfreight消耗的时间是(毫秒):" + (end - start));
start = System.currentTimeMillis();
HttpEntity entity = response.getEntity();
String html = EntityUtils.toString(entity, "utf-8");
end = System.currentTimeMillis();
System.out.println("转换时间:" + (end - start));
String html = EntityUtils.toString(entity, "utf-8");
这一行代码要执行很久 4-9s,我有什么办法把他加快吗
下面是EntityUtils.toString()的方法,包为
public static String toString(HttpEntity entity, Charset defaultCharset) throws IOException, ParseException {
Args.notNull(entity, "Entity");
InputStream instream = entity.getContent();
if (instream == null) {
return null;
} else {
try {
Args.check(entity.getContentLength() <= 2147483647L, "HTTP entity too large to be buffered in memory");
int i = (int)entity.getContentLength();
if (i < 0) {
i = 4096;
}
Charset charset = null;
try {
ContentType contentType = ContentType.get(entity);
if (contentType != null) {
charset = contentType.getCharset();
}
} catch (UnsupportedCharsetException var13) {
if (defaultCharset == null) {
throw new UnsupportedEncodingException(var13.getMessage());
}
}
if (charset == null) {
charset = defaultCharset;
}
if (charset == null) {
charset = HTTP.DEF_CONTENT_CHARSET;
}
Reader reader = new InputStreamReader(instream, charset);
CharArrayBuffer buffer = new CharArrayBuffer(i);
char[] tmp = new char[1024];
int l;
while((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
String var9 = buffer.toString();
return var9;
} finally {
instream.close();
}
}
}
所以EntityUtils的这个方法的逻辑是什么呢。。。