Refactored code to use IOUtils.closeQuietly() to close streams instead of nested try blocks