From 839769b57e661fb08abf023c4cc5fed866d650ae Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 23 Apr 2023 23:06:34 +0200 Subject: [PATCH] Cleanup after "veryLargeJar" test --- .../plexus/archiver/jar/JarArchiverTest.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java b/src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java index dda773d46..b98210928 100644 --- a/src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java +++ b/src/test/java/org/codehaus/plexus/archiver/jar/JarArchiverTest.java @@ -55,18 +55,18 @@ public void testNonCompressed() throws IOException, ManifestException, ArchiverE } @Test - public void testVeryLargeJar() throws IOException, ManifestException, ArchiverException { + public void testVeryLargeJar() throws IOException, ArchiverException { // Generate some number of random files that is likely to be // two or three times the number of available file handles Random rand = new Random(); for (int i = 0; i < 45000; i++) { Path path = tempDir.resolve("file" + i); - OutputStream out = Files.newOutputStream(path); - byte[] data = new byte[512]; // 512bytes per file - rand.nextBytes(data); - out.write(data); - out.flush(); - out.close(); + try (OutputStream out = Files.newOutputStream(path)) { + byte[] data = new byte[512]; // 512bytes per file + rand.nextBytes(data); + out.write(data); + out.flush(); + } } File jarFile = new File("target/output/veryLargeJar.jar"); @@ -75,6 +75,8 @@ public void testVeryLargeJar() throws IOException, ManifestException, ArchiverEx archiver.setDestFile(jarFile); archiver.addDirectory(tempDir.toFile()); archiver.createArchive(); + // Clean up + Files.delete(jarFile.toPath()); } @Test