mirror of
https://github.com/qaiu/netdisk-fast-download.git
synced 2026-06-10 23:47:29 +00:00
fix(parser): JsScriptLoader JarFile 改用 try-with-resources 防止文件句柄泄漏
JarFile 在手动 close() 时若中间抛异常会导致文件句柄未关闭, 改为 try-with-resources 确保无论正常或异常都能释放资源。
This commit is contained in:
@@ -139,21 +139,20 @@ public class JsScriptLoader {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
String jarPath = jarUrl.getPath().substring(5, jarUrl.getPath().indexOf("!"));
|
String jarPath = jarUrl.getPath().substring(5, jarUrl.getPath().indexOf("!"));
|
||||||
JarFile jarFile = new JarFile(jarPath);
|
|
||||||
|
try (JarFile jarFile = new JarFile(jarPath)) {
|
||||||
Enumeration<JarEntry> entries = jarFile.entries();
|
Enumeration<JarEntry> entries = jarFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
JarEntry entry = entries.nextElement();
|
JarEntry entry = entries.nextElement();
|
||||||
String entryName = entry.getName();
|
String entryName = entry.getName();
|
||||||
|
|
||||||
if (entryName.startsWith(RESOURCE_PATH + "/") &&
|
if (entryName.startsWith(RESOURCE_PATH + "/") &&
|
||||||
entryName.endsWith(".js") &&
|
entryName.endsWith(".js") &&
|
||||||
!isExcludedFile(entryName.substring(entryName.lastIndexOf('/') + 1))) {
|
!isExcludedFile(entryName.substring(entryName.lastIndexOf('/') + 1))) {
|
||||||
resourceFiles.add(entryName);
|
resourceFiles.add(entryName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
jarFile.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.debug("解析JAR包资源文件失败", e);
|
log.debug("解析JAR包资源文件失败", e);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user