public static void writeAll ( GatheringByteChannel ch , ByteBuffer [ ] bbs , int offset , int length ) throws IOException { long all = 0 ; for ( int ii = 0 ; ii < length ; ii ++ ) { all += bbs [ offset + ii ] . remaining ( ) ; } int count = 0 ; while ( all > 0 ) { long rc = ch . write ( bbs , offset , length ) ; if ( rc == 0 ) { count ++ ; } else { all -= rc ; } if ( count > 100 ) { throw new IOException ( "Couldn't write all." ) ; } } }
Attempts to write all remaining data in bbs .