use of org.nutz.lang.stream.VoidInputStream in project nutz by nutzam.
the class Sender method createResponse.
protected Response createResponse(Map<String, String> reHeaders) throws IOException {
Response rep = null;
if (reHeaders != null) {
rep = new Response(conn, reHeaders);
if (rep.isOK()) {
InputStream is1 = conn.getInputStream();
InputStream is2 = null;
String encoding = conn.getContentEncoding();
// 如果采用了压缩,则需要处理否则都是乱码
if (encoding != null && encoding.contains("gzip")) {
is2 = new GZIPInputStream(is1);
} else if (encoding != null && encoding.contains("deflate")) {
is2 = new InflaterInputStream(is1, new Inflater(true));
} else {
is2 = is1;
}
BufferedInputStream is = new BufferedInputStream(is2);
rep.setStream(is);
} else {
try {
rep.setStream(conn.getInputStream());
} catch (IOException e) {
try {
rep.setStream(conn.getErrorStream());
} catch (Exception e1) {
rep.setStream(new VoidInputStream());
}
}
}
}
if (this.interceptor != null)
this.interceptor.afterResponse(request, conn, rep);
return rep;
}
Aggregations