You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by hu...@apache.org on 2022/12/07 12:01:02 UTC
[iotdb] branch rel/1.0 updated: [To rel/1.0] replace FileUtils.listFiles in TriggerClassLoader and UDFClassLoader with Files.walk (#8363)
This is an automated email from the ASF dual-hosted git repository.
hui pushed a commit to branch rel/1.0
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/rel/1.0 by this push:
new a0b3c52942 [To rel/1.0] replace FileUtils.listFiles in TriggerClassLoader and UDFClassLoader with Files.walk (#8363)
a0b3c52942 is described below
commit a0b3c52942f0365ef5392555ecb71a387263069a
Author: Liao Lanyu <14...@qq.com>
AuthorDate: Wed Dec 7 20:00:53 2022 +0800
[To rel/1.0] replace FileUtils.listFiles in TriggerClassLoader and UDFClassLoader with Files.walk (#8363)
---
.../iotdb/commons/udf/service/UDFClassLoader.java | 20 +++++++++++---------
.../iotdb/db/trigger/service/TriggerClassLoader.java | 19 +++++++++++--------
2 files changed, 22 insertions(+), 17 deletions(-)
diff --git a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
index ebbe4d65b8..df5dd977b5 100644
--- a/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
+++ b/node-commons/src/main/java/org/apache/iotdb/commons/udf/service/UDFClassLoader.java
@@ -21,14 +21,14 @@ package org.apache.iotdb.commons.udf.service;
import org.apache.iotdb.commons.file.SystemFileFactory;
-import org.apache.commons.io.FileUtils;
-
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.HashSet;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
public class UDFClassLoader extends URLClassLoader {
@@ -55,11 +55,13 @@ public class UDFClassLoader extends URLClassLoader {
}
private void addURLs() throws IOException {
- HashSet<File> fileSet =
- new HashSet<>(FileUtils.listFiles(SystemFileFactory.INSTANCE.getFile(libRoot), null, true));
- URL[] urls = FileUtils.toURLs(fileSet.toArray(new File[0]));
- for (URL url : urls) {
- super.addURL(url);
+ try (Stream<Path> pathStream =
+ Files.walk(SystemFileFactory.INSTANCE.getFile(libRoot).toPath())) {
+ // skip directory
+ for (Path path :
+ pathStream.filter(path -> !path.toFile().isDirectory()).collect(Collectors.toList())) {
+ super.addURL(path.toUri().toURL());
+ }
}
}
diff --git a/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerClassLoader.java b/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerClassLoader.java
index b344ccb338..dd3be0e720 100644
--- a/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerClassLoader.java
+++ b/server/src/main/java/org/apache/iotdb/db/trigger/service/TriggerClassLoader.java
@@ -21,15 +21,16 @@ package org.apache.iotdb.db.trigger.service;
import org.apache.iotdb.commons.file.SystemFileFactory;
-import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
-import java.util.HashSet;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
public class TriggerClassLoader extends URLClassLoader {
@@ -45,11 +46,13 @@ public class TriggerClassLoader extends URLClassLoader {
}
private void addURLs() throws IOException {
- HashSet<File> fileSet =
- new HashSet<>(FileUtils.listFiles(SystemFileFactory.INSTANCE.getFile(libRoot), null, true));
- URL[] urls = FileUtils.toURLs(fileSet.toArray(new File[0]));
- for (URL url : urls) {
- super.addURL(url);
+ try (Stream<Path> pathStream =
+ Files.walk(SystemFileFactory.INSTANCE.getFile(libRoot).toPath())) {
+ // skip directory
+ for (Path path :
+ pathStream.filter(path -> !path.toFile().isDirectory()).collect(Collectors.toList())) {
+ super.addURL(path.toUri().toURL());
+ }
}
}
}