public synchronized int read ( int plane , byte data [ ] , int offset , int length ) throws IOException { if ( offset < 0 || length < 0 || length > data . length - offset ) throw new IndexOutOfBoundsException ( ) ; if ( bytesToRead [ plane ] == 0 ) return 0 ; if ( bytesToRead [ plane ] < length ) length = bytesToRead [ plane ] ; buffer [ plane ] . position ( readPointer [ plane ] ) ; int partLength = buffer [ plane ] . capacity ( ) - readPointer [ plane ] ; if ( partLength > length ) { buffer [ plane ] . get ( data , offset , length ) ; readPointer [ plane ] += length ; } else { buffer [ plane ] . get ( data , offset , partLength ) ; buffer [ plane ] . position ( 0 ) ; buffer [ plane ] . get ( data , partLength , length - partLength ) ; readPointer [ plane ] = length - partLength ; } bytesToRead [ plane ] -= length ; bytesToWrite [ plane ] += length ; return length ; }
Read as much data as possible from this buffer .