public static void writeFully ( ByteBuffer buffer , WritableByteChannel channel ) throws IOException { while ( buffer . hasRemaining ( ) ) { channel . write ( buffer ) ; } }
Writes the entire remaining contents of the buffer to the channel . May complete in one operation but the documentation is vague so this keeps going until we are sure .