Fix a potential resource leak

A FileOutputStream was not closed in case of an exception
Merge pull request #123 from schnappi/ResourceLeakFix

Fix a potential resource leak