private int overlayBytes ( byte [ ] data , int inOffset , int inLength , int inIndex ) { int length = inLength ; int offset = inOffset ; int index = inIndex ; WsByteBuffer buffer = this . parseBuffers [ index ] ; if ( - 1 == length ) { length = data . length ; } while ( index <= this . parseIndex ) { int remaining = buffer . remaining ( ) ; if ( remaining >= length ) { // it all fits now buffer . put ( data , offset , length ) ; return index ; } // put what we can, loop through the next buffer buffer . put ( data , offset , remaining ) ; offset += remaining ; length -= remaining ; buffer = this . parseBuffers [ ++ index ] ; buffer . position ( 0 ) ; } return index ; }
Utility method to overlay the input bytes into the parse buffers starting at the input index and moving forward as needed .