[NEXUS-5831] Use Java7 try-with-resource

Signed-off-by: Alin Dreghiciu <adreghiciu@gmail.com>