-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.java
More file actions
82 lines (75 loc) · 2.23 KB
/
Util.java
File metadata and controls
82 lines (75 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public final class Util {
private static final Log log = LogFactory.getLog(Util.class);
private static final String LIBPATH = System.getProperty("user.dir")
+ System.getProperty("file.separator") + "lib"
+ System.getProperty("file.separator");
public static String toChs(String str) {
if (str == null) {
return "";
}
try {
return new String(str.getBytes(Config
.getValue("database.encode","GB18030")));
} catch (UnsupportedEncodingException e) {
log.error(e);
}
return "";
}
public static URL[] getLibPath(String pluginName) {
URL[] urls = new URL[0];
File fd = new File(LIBPATH + pluginName);
File lst = new File(LIBPATH + pluginName+System.getProperty("file.separator")+"liblst");
if (lst.exists()) {
try {
StringBuilder fc = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(new FileInputStream(lst)));
String line = null;
while ((line = reader.readLine()) != null) {
fc.append(line);
}
if (fc.length() > 0) {
String[] tmp = fc.toString().split(",");
ArrayList<URL> list = new ArrayList<URL>();
for (int i = 0; i < tmp.length; i++) {
try {
File jf = new File(LIBPATH + pluginName+ System.getProperty("file.separator") + tmp[i].trim());
if (jf.exists()) {
list.add(jf.toURL());
}
} catch (Exception e) {
e.printStackTrace();
}
}
urls = new URL[list.size()];
urls = list.toArray(urls);
return urls;
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (fd.isDirectory()) {
File[] f = fd.listFiles();
urls = new URL[f.length];
for (int i = 0; i < f.length; i++) {
try {
urls[i] = (f[i].toURL());
} catch (MalformedURLException e) {
log.error(e.getMessage(), e);
}
}
}
return urls;
}
}