user rmdir to delete temp directory added with
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
+import java.nio.file.Files;
import java.util.Enumeration;
import java.util.Random;
import java.util.zip.ZipEntry;
@@ -2437,9 +2438,7 @@ private static void withTemporaryArchive(final String testName,
File f = getTempFile(testName);
File dir = null;
if (splitSize != null) {
- dir = File.createTempFile("commons-compress-" + testName, "");
- dir.delete();
- dir.mkdir();
+ dir = Files.createTempDirectory("commons-compress-" + testName).toFile();
dir.deleteOnExit();
f = new File(dir, "commons-compress-" + testName + ".zip");
@@ -2462,17 +2461,17 @@ private static void withTemporaryArchive(final String testName,
} finally {
try {
zos.destroy();
- if (dir != null) {
- for (File file : dir.listFiles()) {
- file.delete();
- }
- dir.delete();
- }
} finally {
+ try {
if (os != null) {
os.close();
}
AbstractTestCase.tryHardToDelete(f);
+ } finally {
+ if (dir != null) {
+ AbstractTestCase.rmdir(dir);
+ }
+ }
}
}
}
