@@ -25,14 +25,13 @@ public class ArchiveUtils {
25
25
public static File createZipArchive (String dir , String archiveFileName ) throws DiagnosticException {
26
26
File srcDir = new File (dir );
27
27
String filename = dir + "-" + archiveFileName + ".zip" ;
28
- File file = new File (filename );
29
28
30
29
try (
31
30
FileOutputStream fout = new FileOutputStream (filename );
32
31
ZipArchiveOutputStream taos = new ZipArchiveOutputStream (fout )) {
33
32
archiveResultsZip (archiveFileName , taos , srcDir , null , true );
34
33
logger .info (Constants .CONSOLE , "Archive: " + filename + " was created" );
35
- return file ;
34
+ return new File ( filename ) ;
36
35
} catch (IOException ioe ) {
37
36
throw new DiagnosticException ("Couldn't create zip archive." , ioe );
38
37
}
@@ -51,15 +50,15 @@ private static void archiveResultsZip(
51
50
relPath += "-" + archiveFilename ;
52
51
}
53
52
54
- zipFileStream .putArchiveEntry (new ZipArchiveEntry (file , relPath ));
55
-
56
53
if (file .isFile ()) {
54
+ zipFileStream .putArchiveEntry (new ZipArchiveEntry (file , relPath ));
55
+
57
56
try (BufferedInputStream bis = new BufferedInputStream (new FileInputStream (file ))) {
58
57
IOUtils .copy (bis , zipFileStream );
58
+ } finally {
59
59
zipFileStream .closeArchiveEntry ();
60
60
}
61
61
} else if (file .isDirectory ()) {
62
- zipFileStream .closeArchiveEntry ();
63
62
for (File childFile : file .listFiles ()) {
64
63
archiveResultsZip (archiveFilename , zipFileStream , childFile , relPath , false );
65
64
}
0 commit comments