Skip to content

Commit 5c59e9d

Browse files
committed
update
1 parent 98f658f commit 5c59e9d

File tree

3 files changed

+48
-23
lines changed

3 files changed

+48
-23
lines changed

lib/utils/DiffUtil.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static List<Integer> getChangedLineNumListInOldVersion(String diffFilePat
99

1010
List<Integer> changedLineNumList = new ArrayList<>();
1111
try {
12-
List<String> diffFileStrList = FileUtil.readFileToStrList(diffFilePath);
12+
List<String> diffFileStrList = FileUtil.readFileToLineList(diffFilePath);
1313
for (String line : diffFileStrList) {
1414
if (line.startsWith("@@")) {
1515
for (String tmp : line.split(" ")) {
@@ -35,7 +35,7 @@ public static List<Integer> getChangedLineNumListInNewVersion(String diffFilePat
3535

3636
List<Integer> changedLineNumList = new ArrayList<>();
3737
try {
38-
List<String> diffFileStrList = FileUtil.readFileToStrList(diffFilePath);
38+
List<String> diffFileStrList = FileUtil.readFileToLineList(diffFilePath);
3939
for (String line : diffFileStrList) {
4040
if (line.startsWith("@@")) {
4141
for (String tmp : line.split(" ")) {
@@ -62,7 +62,7 @@ public static List<String> getModifiedFileList(String diffFilePath) {
6262
* can to be further improved in future
6363
*/
6464
List<String> modifiedFileRelPathList = new ArrayList<String>();
65-
for (String line : FileUtil.readFileToStrList(diffFilePath)) {
65+
for (String line : FileUtil.readFileToLineList(diffFilePath)) {
6666
if (line.startsWith("diff --git ")) {
6767
// Heuristic
6868
String fileRelPath = line.replace("diff --git ", "").split(" ")[0].replaceFirst("a/", "").trim();

lib/utils/FileUtil.java

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.io.InputStreamReader;
1313
import java.io.Writer;
1414
import java.nio.file.Files;
15-
import java.nio.file.Path;
1615
import java.nio.file.Paths;
1716
import java.util.ArrayList;
1817
import java.util.List;
@@ -32,9 +31,13 @@ public static String getFileContent(String filePath) throws IOException {
3231
line = br.readLine();
3332
}
3433
return sb.toString();
35-
3634
}
3735

36+
37+
/**
38+
* use new File(PathString).listfiles(File::isDirectory) instead
39+
*/
40+
@Deprecated
3841
public static String[] getSubDirs(String rootDir) {
3942

4043
File file = new File(rootDir);
@@ -53,12 +56,11 @@ public static String readFile2Str(String fpath) {
5356
try {
5457
content = new String(Files.readAllBytes(Paths.get(fpath)));
5558
} catch (IOException e) {
56-
System.out.printf("%f not found!", fpath);
59+
System.out.printf("%s not found!", fpath);
5760
e.printStackTrace();
5861
System.exit(0);
5962
}
6063
return content;
61-
6264
}
6365

6466
public static Boolean writeStr2File(String wStr, String fPath) {
@@ -72,6 +74,33 @@ public static Boolean writeStr2File(String wStr, String fPath) {
7274
return true;
7375
}
7476

77+
public static Boolean copyFile2Dir(File f, String DestDir) {
78+
try {
79+
File DestDirFile = new File(DestDir);
80+
if (!DestDirFile.exists()) {
81+
DestDirFile.mkdirs();
82+
}
83+
String targetFilePath = DestDirFile.getAbsoluteFile() + "/" + f.getName();
84+
FileUtils.copyFile(f, new File(targetFilePath));
85+
} catch (IOException e) {
86+
// TODO Auto-generated catch block
87+
e.printStackTrace();
88+
return false;
89+
}
90+
return true;
91+
}
92+
93+
public static Boolean copyFile2File(File srcFile, File dstFile) {
94+
try {
95+
FileUtils.copyFile(srcFile, dstFile);
96+
} catch (IOException e) {
97+
// TODO Auto-generated catch block
98+
e.printStackTrace();
99+
return false;
100+
}
101+
return true;
102+
}
103+
75104
public static boolean deleteDirectory(String dirPath) {
76105
File directoryToBeDeleted = new File(dirPath);
77106
File[] allContents = directoryToBeDeleted.listFiles();
@@ -83,16 +112,6 @@ public static boolean deleteDirectory(String dirPath) {
83112
return directoryToBeDeleted.delete();
84113
}
85114

86-
public static void copyFolder(Path srcDirStr, Path destDirStr) {
87-
File source = new File(srcDirStr.toString());
88-
File dest = new File(destDirStr.toString());
89-
try {
90-
FileUtils.copyDirectory(source, dest);
91-
} catch (IOException e) {
92-
e.printStackTrace();
93-
}
94-
}
95-
96115
public static void copyFolder(String srcDirStr, String destDirStr) {
97116
File source = new File(srcDirStr);
98117
File dest = new File(destDirStr);
@@ -156,7 +175,13 @@ public static String readStringFromFile(String filePath) {
156175
return null;
157176
}
158177

159-
public static List<String> readFileToStrList(String filePath) {
178+
/**
179+
* there is no \newline at the end of each line
180+
*
181+
* @param filePath
182+
* @return
183+
*/
184+
public static List<String> readFileToLineList(String filePath) {
160185
ArrayList<String> strList = new ArrayList<String>();
161186
try {
162187
if (!new File(filePath).exists()) {
@@ -202,21 +227,21 @@ public static boolean deleteDirectory(File directoryToBeDeleted) {
202227
return directoryToBeDeleted.delete();
203228
}
204229

205-
public static List<String> findFilePathofSpecifcTypeRecusive(String tarDir, String extension) {
230+
public static List<File> findFilePathofSpecifcTypeRecusive(String tarDir, String extension) {
206231

207-
List<String> pathList = new ArrayList<String>();
232+
List<File> fileList = new ArrayList<File>();
208233
try {
209234
Files.walk(Paths.get(tarDir)).filter(Files::isRegularFile).forEach((f) -> {
210235
String filepath = f.toString();
211236
if (filepath.endsWith(extension))
212237
// System.out.println(file + " found!");
213-
pathList.add(filepath);
238+
fileList.add(new File(filepath));
214239
});
215240
} catch (IOException e) {
216241
// TODO Auto-generated catch block
217242
e.printStackTrace();
218243
}
219-
return pathList;
244+
return fileList;
220245
}
221246

222247
public static List<String> findRelativeFilePathofSpecifcTypeRecusive(String tarDir, String extension) {

lib/utils/SRCUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
public class SRCUtil {
66

77
public static void changePackage(String oriSRCPath, String dstSRCPath, String newPackName) {
8-
List<String> srcStrList = FileUtil.readFileToStrList(oriSRCPath);
8+
List<String> srcStrList = FileUtil.readFileToLineList(oriSRCPath);
99

1010
Boolean ifchanged = false;
1111
String wrtStr = "";

0 commit comments

Comments
 (0)