FileUtils.java
3.7 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package com.vion.utils;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
/**
* @author 谢明辉
* @createDate 2018-10-30
* @description
*/
public class FileUtils {
public static Pattern pattern = Pattern.compile("[0-9]{8}");
public static void getFiles(List<File> fileList, String basePath, Integer begin, Integer end) {
File file = new File(basePath);
if (!file.exists()) {
System.out.println(basePath + " 不存在");
return;
}
File[] files = file.listFiles();
if (files != null) {
for (File file1 : files) {
if (file1.isDirectory()) {
if (file1.getName().matches("[0-9]{8}")) {
if (Integer.parseInt(file1.getName()) >= begin && Integer.parseInt(file1.getName()) <= end) {
getFiles(fileList, getAvailablePath(file1), begin, end);
}
} else {
getFiles(fileList, getAvailablePath(file1), begin, end);
}
} else {
if (file1.getName().contains("face-0") || file1.getName().contains("body-0")) {
fileList.add(file1);
}
}
}
}
}
private static String getAvailablePath(File file) {
return file.getPath().replace("//", "/");
}
public static String generator(String name, String pathPrefix, String pathPostfix, String channelSerialNum) {
StringBuilder result = new StringBuilder();
if (pathPrefix != null) {
result.append(pathPrefix);
}
if (pathPostfix != null) {
if (name.endsWith(pathPostfix)) {
name = name.substring(0, name.lastIndexOf(pathPostfix));
}
}
if (name.contains("face")) {
result.append("face").append("/");
} else if (name.contains("body")) {
result.append("body").append("/");
}
if (name.length() > 25) {
String dateStr = name.substring(name.length() - 25, name.length() - 17);
result.append(dateStr).append("/");
}
result.append(channelSerialNum).append("/").append(name);
if (pathPostfix != null) {
result.append(pathPostfix);
}
return result.toString();
}
public static <T> List<List<T>> averageAssign(List<T> source, int n) {
List<List<T>> result = new ArrayList<List<T>>();
//余数
int remainder = source.size() % n;
//商
int number = source.size() / n;
//偏移量
int offset = 0;
for (int i = 0; i < n; i++) {
List<T> value = null;
if (remainder > 0) {
value = source.subList(i * number + offset, (i + 1) * number + offset + 1);
remainder--;
offset++;
} else {
value = source.subList(i * number + offset, (i + 1) * number + offset);
}
result.add(value);
}
return result;
}
public static boolean isNotNull(String s) {
return !(s == null || "".equals(s));
}
public static String getPathName(String basePath, Integer dateNumber, String channelSerialNum, String fileName, boolean isFeature) {
StringBuilder sb = new StringBuilder();
sb.append(basePath).append(dateNumber).append("\\");
if (isNotNull(channelSerialNum)) {
sb.append(channelSerialNum).append("\\");
}
sb.append(fileName);
if (isFeature) {
sb.append(".feature");
}
return sb.toString();
}
}