Replace calls to ByteStreams2.toByteArrayAndClose

Prefer try-with-resources.