From 9fd7d968c823b396fe89bfacbd69365c50430e95 Mon Sep 17 00:00:00 2001 From: Alfusainey Jallow Date: Mon, 10 Jul 2023 09:36:28 +0200 Subject: [PATCH] [LOGBACK-1755] Close streams Signed-off-by: Alfusainey Jallow --- .../logback/core/rolling/helper/CompressTest.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java index f7d617abba..830915ecc3 100755 --- a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java +++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java @@ -111,15 +111,14 @@ public void test3() throws Exception { } private void copy(File src, File dst) throws IOException { - InputStream in = new FileInputStream(src); - OutputStream out = new FileOutputStream(dst); - byte[] buf = new byte[1024]; - int len; - while ((len = in.read(buf)) > 0) { - out.write(buf, 0, len); + try (InputStream in = new FileInputStream(src); + OutputStream out = new FileOutputStream(dst);) { + byte[] buf = new byte[1024]; + int len; + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } } - in.close(); - out.close(); } }