protected long [ ] availableRange ( ) { // for revisit capture, HTTP headers comes from revisiting resource. // it should be okay to assume revisited resource has exactly the same // Content-Range header field. Map < String , String > respHeaders = origResource . getHttpHeaders ( ) ; long [ ] contentRange = HttpHeaderOperation . getContentRange ( respHeaders ) ; long availStart , availStop , contentLength ; if ( contentRange == null ) { // regular 200 response (or Content-Range is invalid) String clen = HttpHeaderOperation . getContentLength ( respHeaders ) ; if ( clen != null ) { try { contentLength = Long . parseLong ( clen ) ; } catch ( NumberFormatException ex ) { return null ; } } else { // no Content-Length - probably chunked encoded - // not supported yet (TODO: determine length by // actually reading?) return null ; } availStart = 0 ; availStop = contentLength ; } else { // 206, or perhaps 416 response if ( contentRange [ 0 ] < 0 ) { // 416 (both [0] and [1] are -1 for */instance-length) return null ; } availStart = contentRange [ 0 ] ; availStop = contentRange [ 1 ] ; contentLength = contentRange [ 2 ] ; // TODO: need support for M-N/*? if ( contentLength < 0 ) return null ; // sanity check if ( availStop <= availStart ) return null ; if ( contentLength < availStop ) return null ; } return new long [ ] { availStart , availStop , contentLength } ; }
Look at resource HTTP header fields and determine the byte range available .