if (conn instanceof HttpURLConnection)
((HttpURLConnection) conn).setFollowRedirects(true);
InputStream is = conn.getInputStream();
try {
ReadStream in = Vfs.openRead(is);
String encoding = conn.getContentEncoding();
String contentType = conn.getContentType();
if (_charEncoding != null) {
encoding = _charEncoding;
if (encoding != null && ! encoding.equals(""))
in.setEncoding(encoding);
}
else if (encoding != null)
in.setEncoding(encoding);
else if (contentType != null) {
int p = contentType.indexOf("charset=");
if (p > 0) {
CharBuffer cb = new CharBuffer();
for (int i = p + 8; i < contentType.length(); i++) {
int ch = contentType.charAt(i);
if (ch == '"' || ch == '\'') {
}
else if (ch >= 'a' && ch <= 'z')
cb.append((char) ch);
else if (ch >= 'A' && ch <= 'Z')
cb.append((char) ch);
else if (ch >= '0' && ch <= '9')
cb.append((char) ch);
else if (ch == '-' || ch == '_')
cb.append((char) ch);
else
break;
}
encoding = cb.toString();
in.setEncoding(encoding);
}
}
JspWriter out = pageContext.getOut();
int ch;
while ((ch = in.readChar()) >= 0)
out.print((char) ch);
} finally {
is.close();
}
}