use Files.newInputStream instead of new FileInputStream and null check (#10847)
This commit is contained in:
parent
d7c8d10dbf
commit
1aa1aea43e
|
|
@ -56,15 +56,18 @@ public class ClassFinder {
|
||||||
private void findClassesByFile(String packageName, String resource, Set<String> result) {
|
private void findClassesByFile(String packageName, String resource, Set<String> result) {
|
||||||
File directory = new File(resource);
|
File directory = new File(resource);
|
||||||
File[] listFiles = directory.listFiles();
|
File[] listFiles = directory.listFiles();
|
||||||
for (File file : listFiles) {
|
// null check
|
||||||
if (file.isDirectory()) {
|
if (listFiles != null) {
|
||||||
findClassesByFile(packageName, file.getPath(), result);
|
for (File file : listFiles) {
|
||||||
} else {
|
if (file.isDirectory()) {
|
||||||
String path = file.getPath();
|
findClassesByFile(packageName, file.getPath(), result);
|
||||||
if (path.endsWith(".class")) {
|
} else {
|
||||||
int packageIndex = path.indexOf(packageName.replace("/", File.separator));
|
String path = file.getPath();
|
||||||
String classPath = path.substring(packageIndex, path.length() - 6);
|
if (path.endsWith(".class")) {
|
||||||
result.add(classPath.replace(File.separator, "."));
|
int packageIndex = path.indexOf(packageName.replace("/", File.separator));
|
||||||
|
String classPath = path.substring(packageIndex, path.length() - 6);
|
||||||
|
result.add(classPath.replace(File.separator, "."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,15 +56,17 @@ public class ClassFinder {
|
||||||
private void findClassesByFile(String packageName, String resource, Set<String> result) {
|
private void findClassesByFile(String packageName, String resource, Set<String> result) {
|
||||||
File directory = new File(resource);
|
File directory = new File(resource);
|
||||||
File[] listFiles = directory.listFiles();
|
File[] listFiles = directory.listFiles();
|
||||||
for (File file : listFiles) {
|
if (listFiles != null) {
|
||||||
if (file.isDirectory()) {
|
for (File file : listFiles) {
|
||||||
findClassesByFile(packageName, file.getPath(), result);
|
if (file.isDirectory()) {
|
||||||
} else {
|
findClassesByFile(packageName, file.getPath(), result);
|
||||||
String path = file.getPath();
|
} else {
|
||||||
if (path.endsWith(".class")) {
|
String path = file.getPath();
|
||||||
int packageIndex = path.indexOf(packageName.replace("/", File.separator));
|
if (path.endsWith(".class")) {
|
||||||
String classPath = path.substring(packageIndex, path.length() - 6);
|
int packageIndex = path.indexOf(packageName.replace("/", File.separator));
|
||||||
result.add(classPath.replace(File.separator, "."));
|
String classPath = path.substring(packageIndex, path.length() - 6);
|
||||||
|
result.add(classPath.replace(File.separator, "."));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ import org.apache.dubbo.test.check.exception.DubboTestException;
|
||||||
import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext;
|
import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
@ -54,7 +53,8 @@ public class ConfigZookeeperInitializer extends ZookeeperInitializer {
|
||||||
int availableAdminServerPort = NetUtils.getAvailablePort(adminServerPort);
|
int availableAdminServerPort = NetUtils.getAvailablePort(adminServerPort);
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
try {
|
try {
|
||||||
properties.load(new FileInputStream(zooSample));
|
// use Files.newInputStream instead of new FileInputStream
|
||||||
|
properties.load(Files.newInputStream(zooSample.toPath()));
|
||||||
properties.setProperty("clientPort", String.valueOf(clientPort));
|
properties.setProperty("clientPort", String.valueOf(clientPort));
|
||||||
properties.setProperty("admin.serverPort", String.valueOf(availableAdminServerPort));
|
properties.setProperty("admin.serverPort", String.valueOf(availableAdminServerPort));
|
||||||
Path dataDir = Paths.get(zookeeperConf.getParent().toString(), "data");
|
Path dataDir = Paths.get(zookeeperConf.getParent().toString(), "data");
|
||||||
|
|
@ -87,7 +87,8 @@ public class ConfigZookeeperInitializer extends ZookeeperInitializer {
|
||||||
|
|
||||||
File log4j = Paths.get(zookeeperConf.toString(), "log4j.properties").toFile();
|
File log4j = Paths.get(zookeeperConf.toString(), "log4j.properties").toFile();
|
||||||
try {
|
try {
|
||||||
properties.load(new FileInputStream(log4j));
|
// use Files.newInputStream instead of new FileInputStream
|
||||||
|
properties.load(Files.newInputStream(log4j.toPath()));
|
||||||
Path logDir = Paths.get(zookeeperConf.getParent().toString(), "logs");
|
Path logDir = Paths.get(zookeeperConf.getParent().toString(), "logs");
|
||||||
if (!Files.exists(logDir)) {
|
if (!Files.exists(logDir)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue