MCPcopy Create free account
hub / github.com/apache/nutch / isTruncated

Method isTruncated

src/java/org/apache/nutch/parse/ParserJob.java:179–211  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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();

Callers 4

outputMethod · 0.95
runMethod · 0.95
runMethod · 0.95
mapMethod · 0.80

Calls 5

isEmptyMethod · 0.95
getContentMethod · 0.65
getMethod · 0.65
getHeadersMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected