Refactoring

using try-with-resources

Signed-off-by: Dominik Schadow <dominikschadow@googlemail.com>