public int read ( byte [ ] array , int offset , int length ) { if ( curr == null ) return - 1 ; int len ; int count = 0 ; while ( length > 0 ) { // loop through while there's data needed if ( ( len = curr . remaining ( ) ) > length ) { // if enough data in curr buffer, use this code curr . get ( array , offset , length ) ; count += length ; length = 0 ; } else { // get data from curr, mark how much is needed to fulfil, and loop for next curr. curr . get ( array , offset , len ) ; count += len ; offset += len ; length -= len ; if ( idx < bbs . size ( ) ) { curr = bbs . get ( idx ++ ) ; } else { length = 0 ; // stop, and return the count of how many we were able to load } } } return count ; }
read into an array like Streams