Method for calculating finite size corrections in Bethe ansatz systems: Heisenberg chain and six-vertex model