@ Override public synchronized void seek ( long targetPos ) throws IOException { if ( targetPos > getFileLength ( ) ) { throw new IOException ( "Cannot seek after EOF" ) ; } boolean done = false ; if ( pos <= targetPos && targetPos <= blockEnd ) { // // If this seek is to a positive position in the current // block, and this piece of data might already be lying in // the TCP buffer, then just eat up the intervening data. // int diff = ( int ) ( targetPos - pos ) ; if ( diff <= DFSClient . TCP_WINDOW_SIZE ) { try { pos += blockReader . skip ( diff ) ; if ( pos == targetPos ) { done = true ; } } catch ( IOException e ) { //make following read to retry dfsClient . incReadExpCntToStats ( ) ; DFSClient . LOG . debug ( "Exception while seek to " + targetPos + " from " + currentBlock + " of " + src + " from " + currentNode + ": " + StringUtils . stringifyException ( e ) ) ; } } else { if ( DFSClient . LOG . isDebugEnabled ( ) ) { DFSClient . LOG . debug ( "seek() out of TCP buffer " + " block " + currentBlock + " current pos: " + pos + " target pos: " + targetPos ) ; } } } if ( ! done ) { pos = targetPos ; blockEnd = - 1 ; } }
Seek to a new arbitrary location