@@ -29,13 +29,22 @@ public boolean isInBlacklist(String input) {
29
29
30
30
@ Override
31
31
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 ());
34
39
}
35
40
36
41
@ Override
37
42
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
+ }
39
48
}
40
49
41
50
@ Override
@@ -53,9 +62,13 @@ public ReadZipStreamStrategy newReaderStrategyWithTmp(Path tmpDirectory, boolean
53
62
54
63
@ Override
55
64
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
+ }
60
73
}
61
74
}
0 commit comments