/** * 将Entity的内容载入Page对象 * * @date 2013-1-7 上午11:22:06 * @param entity * @return * @throws Exception */ private Page load(HttpEntity entity) throws Exception { Page page = new Page(); // 设置返回内容的ContentType String contentType = null; Header type = entity.getContentType(); if (type != null) contentType = type.getValue(); page.setContentType(contentType); // 设置返回内容的字符编码 String contentEncoding = null; Header encoding = entity.getContentEncoding(); if (encoding != null) contentEncoding = encoding.getValue(); page.setEncoding(contentEncoding); // 设置返回内容的字符集 String contentCharset = EntityUtils.getContentCharSet(entity); page.setCharset(contentCharset); // 根据配置文件设置的字符集参数进行内容二进制话 String charset = config.getCharset(); String content = this.read(entity.getContent(), charset); page.setContent(content); // if (charset == null || charset.trim().length() == 0) // page.setContentData(content.getBytes()); // else // page.setContentData(content.getBytes(charset)); return page; }
private void assemPage(FetchResult fetchResult, HttpEntity entity) throws Exception { Page page = load(entity); page.setUrl(fetchResult.getFetchedUrl()); fetchResult.setPage(page); }