public static final long move ( ByteBuffer b1 , ByteBuffer b2 ) { int remaining1 = b1 . remaining ( ) ; int remaining2 = b2 . remaining ( ) ; if ( remaining1 <= remaining2 ) { b2 . put ( b1 ) ; return remaining1 ; } else { int safeLimit = b1 . limit ( ) ; b1 . limit ( b1 . position ( ) + remaining2 ) ; b2 . put ( b1 ) ; b1 . limit ( safeLimit ) ; return remaining2 ; } }
Moves bytes from b1 to b2 as much as is possible . Positions are moved according to move .