From 89af53731feeb0fc8ad1e250c99f9eee6ecd3b1a Mon Sep 17 00:00:00 2001 From: "shi.qin" <397079086@qq.com> Date: Mon, 20 Dec 2021 14:46:26 +0800 Subject: [PATCH] add close --- .../aabresguard/bundle/AppBundleAnalyzer.java | 12 ++++++++++-- .../aabresguard/commands/ObfuscateBundleCommand.java | 4 +++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java index 858cfdb..210fbe3 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/bundle/AppBundleAnalyzer.java @@ -18,6 +18,7 @@ public class AppBundleAnalyzer { private static final Logger logger = Logger.getLogger(AppBundleAnalyzer.class.getName()); private final Path bundlePath; + private ZipFile bundleZip; public AppBundleAnalyzer(Path bundlePath) { checkFileExistsAndReadable(bundlePath); @@ -26,10 +27,17 @@ public AppBundleAnalyzer(Path bundlePath) { public AppBundle analyze() throws IOException { TimeClock timeClock = new TimeClock(); - ZipFile bundleZip = new ZipFile(bundlePath.toFile()); + bundleZip = new ZipFile(bundlePath.toFile()); AppBundle appBundle = AppBundle.buildFromZip(bundleZip); -// bundleZip.close(); System.out.println(String.format("analyze bundle file done, const %s", timeClock.getCoast())); return appBundle; } + + public void closeFile() throws IOException { + if(bundleZip != null){ + bundleZip.close(); + bundleZip = null; + System.out.println(String.format("bundle zip close")); + } + } } diff --git a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java index e027ec3..09721c7 100644 --- a/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java +++ b/core/src/main/java/com/bytedance/android/aabresguard/commands/ObfuscateBundleCommand.java @@ -172,7 +172,8 @@ public static ObfuscateBundleCommand fromFlags(ParsedFlags flags) throws Documen public Path execute() throws IOException, InterruptedException { TimeClock timeClock = new TimeClock(); - AppBundle appBundle = new AppBundleAnalyzer(getBundlePath()).analyze(); + AppBundleAnalyzer analyzer = new AppBundleAnalyzer(getBundlePath()); + AppBundle appBundle = analyzer.analyze(); // filter file if (getFilterFile().isPresent() && getFilterFile().get()) { Set fileFilterRules = new HashSet<>(); @@ -243,6 +244,7 @@ storeFile, getStorePassword().get(), getKeyAlias().get(), getKeyPassword().get() getNetFileSizeDescription(rawSize), getNetFileSizeDescription(filteredSize) )); + analyzer.closeFile(); return getOutputPath(); }