long checkRangeSupport ( URI uri ) throws IOException { HttpRequestBase req = createReq ( uri , true ) ; try ( CloseableHttpClient client = HttpClientBuilder . create ( ) . build ( ) ; CloseableHttpResponse response = client . execute ( req ) ) { Header acceptRangesHeader = response . getFirstHeader ( HttpHeaders . ACCEPT_RANGES ) ; Header contentLengthHeader = response . getFirstHeader ( HttpHeaders . CONTENT_LENGTH ) ; boolean acceptByteRange = ( acceptRangesHeader != null ) && "bytes" . equalsIgnoreCase ( acceptRangesHeader . getValue ( ) ) ; if ( ! acceptByteRange || contentLengthHeader == null ) { return - 1L ; } return Long . valueOf ( contentLengthHeader . getValue ( ) ) ; } }
Tests whether a given URI can be accessed using range - requests .