Replace try-finally with try-with-resources as we have JDK 7.