@ Override public boolean apply ( final HttpResponse httpResponse ) { try { final InputStream content = httpResponse . getEntity ( ) . getContent ( ) ; int count = 0 ; for ( int i = BINARY_CHECK_SCAN_LENGTH ; i -- != 0 ; ) { final int b = content . read ( ) ; if ( b == - 1 ) return false ; if ( b == 0 && ++ count == THRESHOLD ) return true ; } } catch ( final IOException shouldntReallyHappen ) { throw new RuntimeException ( shouldntReallyHappen ) ; } return false ; }
This method implements a simple heuristic for guessing whether a page is binary .