code: public static void writeFully(ByteBuffer buffer, WritableByteChannel channel) throws IOException {
          while (buffer.hasRemaining()) {
              channel.write(buffer);
          }
      }
docs: 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.
  
  @param buffer the data to be written
  @param channel the channel to which we want to write data
  
  @throws IOException if there is a problem writing to the channel