private static void writeFullyImpl(WritableByteChannel ch,ByteBuffer bb) throws IOException {
  while (bb.remaining() > 0) {
    int n=ch.write(bb);
    if (n <= 0)     throw new RuntimeException("no bytes written");
  }
}

private static void writeFullyImpl ( WritableByteChannel ch , ByteBuffer bb ) throws IOException { while ( bb . remaining ( ) > 0 ) { int n = ch . write ( bb ) ; if ( n <= 0 ) throw new RuntimeException ( "no bytes written" ) ; } }
write all remaining bytes in buffer to the given channel . if the channel is selectable then it must be configured blocking .
