private Boolean resultTest(String result) {
if (!result.equals("") && !result.equals("100")
&& !result.contains("<title>blank")
&& !result.contains("Error Page Messages")
&& !result.contains("<title>404")
&& !result.contains("您的访问出错了") && !result.contains("302 Found")
&& !result.contains("出错页面") && !result.contains("没有找到这篇文章!")
&& !result.contains("特定于实例的错误") && !result.contains("错误 404")
&& !result.contains("Error report")
&& !result.contains("function JumpSelf")
&& !result.contains("refused") && !result.contains("网站防火墙")
&& !result.contains("无法解析服务器") && !result.contains("STATUS OK")
&& !result.contains("refresh")
&& !result.contains("DownloadError")
&& !result.contains("Not Found")
&& !result.contains("Runtime Error")
&& !result.contains("Service Unavailable")) {
return true;
}
return false;
}
public static String enCodetoString(final HttpEntity entity,
final String defaultCharset) throws IOException, ParseException {
return enCodetoStringDo(entity,
defaultCharset != null ? Charset.forName(defaultCharset) : null);
}
public static String enCodetoStringDo(final HttpEntity entity,
Charset defaultCharset) throws IOException, ParseException {
if (entity == null) {
throw new IllegalArgumentException("HTTP entity may not be null");
}
InputStream instream = entity.getContent();
if (instream == null) {
return null;
}
try {
if (entity.getContentLength() > Integer.MAX_VALUE) {
throw new IllegalArgumentException(
"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 (final UnsupportedCharsetException ex) {
throw new UnsupportedEncodingException(ex.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);
}
return buffer.toString();
} finally {
instream.close();
}
} |