Fixes off-by-one error in DumpStore

- using try-with-resources when possible