ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try { ... } finally { outputStream.close(); }