Checks if the page's content is truncated. @param url @param page @return If the page is truncated true . When it is not, or when it could be determined, false .
(String url, WebPage page)
| 177 | * it could be determined, <code>false</code>. |
| 178 | */ |
| 179 | public static boolean isTruncated(String url, WebPage page) { |
| 180 | ByteBuffer content = page.getContent(); |
| 181 | if (content == null) { |
| 182 | return false; |
| 183 | } |
| 184 | CharSequence lengthUtf8 = page.getHeaders().get( |
| 185 | new Utf8(HttpHeaders.CONTENT_LENGTH)); |
| 186 | if (lengthUtf8 == null) { |
| 187 | return false; |
| 188 | } |
| 189 | String lengthStr = lengthUtf8.toString().trim(); |
| 190 | if (StringUtil.isEmpty(lengthStr)) { |
| 191 | return false; |
| 192 | } |
| 193 | int inHeaderSize; |
| 194 | try { |
| 195 | inHeaderSize = Integer.parseInt(lengthStr); |
| 196 | } catch (NumberFormatException e) { |
| 197 | LOG.warn("Wrong contentlength format for " + url, e); |
| 198 | return false; |
| 199 | } |
| 200 | int actualSize = content.limit(); |
| 201 | if (inHeaderSize > actualSize) { |
| 202 | LOG.warn(url + " skipped. Content of size " + inHeaderSize |
| 203 | + " was truncated to " + actualSize); |
| 204 | return true; |
| 205 | } |
| 206 | if (LOG.isDebugEnabled()) { |
| 207 | LOG.debug(url + " actualSize=" + actualSize + " inHeaderSize=" |
| 208 | + inHeaderSize); |
| 209 | } |
| 210 | return false; |
| 211 | } |
| 212 | |
| 213 | public Collection<WebPage.Field> getFields(Job job) { |
| 214 | Configuration conf = job.getConfiguration(); |
no test coverage detected