diff --git a/spring-rest-compress/src/main/java/org/baeldung/spring/rest/compress/GzipUtils.java b/spring-rest-compress/src/main/java/org/baeldung/spring/rest/compress/GzipUtils.java index f3cb8bd631..75420ca6d8 100644 --- a/spring-rest-compress/src/main/java/org/baeldung/spring/rest/compress/GzipUtils.java +++ b/spring-rest-compress/src/main/java/org/baeldung/spring/rest/compress/GzipUtils.java @@ -30,15 +30,11 @@ public class GzipUtils { * @throws IOException */ public static byte[] compress(byte[] body) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - try { - try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(output)) { - gzipOutputStream.write(body); - } - } finally { - output.close(); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(baos)) { + gzipOutputStream.write(body); } - return output.toByteArray(); + return baos.toByteArray(); } /**