forked from MasterFlomaster1/JFXCrypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathCutter.java
More file actions
35 lines (31 loc) · 1014 Bytes
/
Copy pathPathCutter.java
File metadata and controls
35 lines (31 loc) · 1014 Bytes
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
package Utils;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.regex.Pattern;
public class PathCutter {
public static String cutPath(String path) {
if (path.length() <= 62) return path;
String pattern = Pattern.quote(System.getProperty("file.separator"));
ArrayList<String> subStr = new ArrayList<>(Arrays.asList(path.split(pattern)));
int size = path.length();
int prev = 0;
while (size>62) {
if (prev!=0) {
subStr.remove(prev);
}
int index = subStr.size()/2;
size-=subStr.get(index).length();
subStr.set(index, "...");
prev = index;
}
StringBuilder str = new StringBuilder();
for (int i = 0; i < subStr.size(); i++) {
str.append(subStr.get(i));
if (i<subStr.size()-1) {
str.append(File.separator);
}
}
return str.toString();
}
}