Remove use of try-with-resources so we support API level 16.

try-with-resources needs API level 19. Actually, it seems to work
on API level 16, but it is still not officially supported,
so android-lint complains about it.

The code is very ugly without try-with-resources, but is fairly correct.
It's still not quite as good as the code that try-with-resources
generates.