@ Override public int read ( byte [ ] b , int off , int len ) throws IOException { // Read from the queue synchronized ( file ) { while ( true ) { long fileLen = file . getLength ( ) ; if ( fileLen >= 1 ) { long pos = file . getFirstIndex ( ) ; file . file . seek ( pos + 16 ) ; int readSize = fileLen > len ? len : ( int ) fileLen ; // When at the end of the file, read the remaining bytes if ( ( pos + readSize ) > file . maxFifoLength ) readSize = ( int ) ( file . maxFifoLength - pos ) ; // Read as many bytes as currently available int totalRead = file . file . read ( b , off , readSize ) ; if ( totalRead == - 1 ) throw new EOFException ( "Unexpected EOF" ) ; addStats ( totalRead ) ; long newFirstIndex = pos + totalRead ; while ( newFirstIndex >= file . maxFifoLength ) newFirstIndex -= file . maxFifoLength ; file . setFirstIndex ( newFirstIndex ) ; file . setLength ( fileLen - totalRead ) ; file . notify ( ) ; return totalRead ; } try { file . wait ( ) ; } catch ( InterruptedException err ) { InterruptedIOException ioErr = new InterruptedIOException ( ) ; ioErr . initCause ( err ) ; throw ioErr ; } } } }
Reads data from the file blocks until at least one byte is available .