diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java index 1e055d619..4ea18e5fd 100755 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFChecker.java @@ -233,6 +233,18 @@ public boolean apply(OPFHandler opfHandler) // checkFileExtension(state); + // Close zip file to free resource + if (state.getZipResources() != null) + { + try + { + state.getZipResources().close(); + } + catch (Exception e) + { + // FIXME 2023 - Inability to close zip file should be handled + } + } } private boolean checkContainerFile(OCFCheckerState state) @@ -275,7 +287,9 @@ private boolean checkContainerStructure(OCFCheckerState state) { // FIXME 2022 build resourcesProvider depending on MIME type // Get a container - Iterable resourcesProvider = new OCFZipResources(context.url); + OCFZipResources resourcesProvider = new OCFZipResources(context.url); + // Store the OCFZipResources object so it can be closed later + state.setZipResources(resourcesProvider); // Set to store the normalized paths for duplicate checks final Set normalizedPaths = new HashSet<>(); // Lists to store the container entries for later empty directory check diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFCheckerState.java b/src/main/java/com/adobe/epubcheck/ocf/OCFCheckerState.java index 5fad42764..4381752a3 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFCheckerState.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFCheckerState.java @@ -41,6 +41,8 @@ class OCFCheckerState private final ImmutableList.Builder packageDocuments = ImmutableList.builder(); private URL mappingDocument; + private OCFZipResources zipResources = null; + private final Map obfuscated = new HashMap<>(); private final Map> publicationTypes = new LinkedHashMap<>(); private final Map publicationIDs = new LinkedHashMap<>(); @@ -84,6 +86,16 @@ public void addResource(OCFResource resource) containerNeedsRebuild = true; } + public OCFZipResources getZipResources() + { + return zipResources; + } + + public void setZipResources(OCFZipResources zipResources) + { + this.zipResources = zipResources; + } + public void addRootfile(String mediaType, URL resource) { Preconditions.checkNotNull(mediaType); diff --git a/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java b/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java index 6ee1bf75c..c523806c2 100644 --- a/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java +++ b/src/main/java/com/adobe/epubcheck/ocf/OCFZipResources.java @@ -98,6 +98,11 @@ public String toString() }; } + public void close() throws IOException + { + zip.close(); + } + private static String getSHAHash(ZipEntry entry, ZipFile zip) { try (InputStream inputStream = zip.getInputStream(entry))