@@ -29,13 +29,22 @@ public boolean isInBlacklist(String input) {
2929
3030 @ Override
3131 public void saveCrate (Crate crate , Path target ) throws IOException {
32- Writers .newZipStreamWriter ().save (crate , new FileOutputStream (target .toFile ()));
33- assertTrue (target .toFile ().isFile ());
32+ final File target_file = target .toFile ();
33+ try (
34+ FileOutputStream fos = new FileOutputStream (target_file )
35+ ) {
36+ Writers .newZipStreamWriter ().save (crate , fos );
37+ }
38+ assertTrue (target_file .isFile ());
3439 }
3540
3641 @ Override
3742 public Crate readCrate (Path source ) throws IOException {
38- return Readers .newZipStreamReader ().readCrate (new FileInputStream (source .toFile ()));
43+ try (
44+ FileInputStream fis = new FileInputStream (source .toFile ())
45+ ) {
46+ return Readers .newZipStreamReader ().readCrate (fis );
47+ }
3948 }
4049
4150 @ Override
@@ -53,9 +62,13 @@ public ReadZipStreamStrategy newReaderStrategyWithTmp(Path tmpDirectory, boolean
5362
5463 @ Override
5564 public Crate readCrate (ReadZipStreamStrategy strategy , Path source ) throws IOException {
56- Crate importedCrate = new CrateReader <>(strategy )
57- .readCrate (new FileInputStream (source .toFile ()));
58- assertTrue (strategy .isExtracted ());
59- return importedCrate ;
65+ try (
66+ FileInputStream fis = new FileInputStream (source .toFile ())
67+ ) {
68+ Crate importedCrate = new CrateReader <>(strategy ).readCrate (fis );
69+ assertNotNull (importedCrate );
70+ assertTrue (strategy .isExtracted ());
71+ return importedCrate ;
72+ }
6073 }
6174}
0 commit comments