write until hasRemaining() == false