]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Common.java
1 package org
.tianocore
.migration
;
4 import java
.util
.regex
.*;
8 public static String
file2string(String filename
) throws Exception
{
9 BufferedReader rd
= new BufferedReader(new FileReader(filename
));
10 StringBuffer wholefile
= new StringBuffer();
12 while ((line
= rd
.readLine()) != null) {
13 wholefile
.append(line
+ "\n");
15 return wholefile
.toString();
18 public static void ensureDir(String objFileWhole
) {
19 Pattern ptnseparate
= Pattern
.compile("(.*)\\\\[^\\\\]*");
23 mtrseparate
= ptnseparate
.matcher(objFileWhole
);
24 if (mtrseparate
.find()) {
25 tempdir
= new File(mtrseparate
.group(1));
26 if (!tempdir
.exists()) tempdir
.mkdirs();
30 public static void string2file(String content
, String filename
) throws Exception
{
32 PrintWriter outfile
= new PrintWriter(new BufferedWriter(new FileWriter(filename
)));
33 outfile
.append(content
);
38 public static HashSet
<String
> dirScan(String path
) { // use HashSet, persue speed rather than space
39 HashSet
<String
> filelist
= new HashSet
<String
>();
40 String
[] list
= new File(path
).list();
43 for (int i
= 0 ; i
< list
.length
; i
++) {
44 test
= new File(path
+ File
.separator
+ list
[i
]);
45 if (test
.isDirectory()) {
46 dirScan(path
+ File
.separator
+ list
[i
]);
48 filelist
.add(path
+ File
.separator
+ list
[i
]);
55 public static void toDoAll(String path
, ForDoAll fda
) throws Exception
{ // filter of file type can be done in toDo
56 String
[] list
= new File(path
).list();
59 for (int i
= 0 ; i
< list
.length
; i
++) {
60 test
= new File(path
+ File
.separator
+ list
[i
]);
61 if (test
.isDirectory()) {
62 toDoAll(path
+ File
.separator
+ list
[i
], fda
);
64 fda
.toDo(path
+ File
.separator
+ list
[i
]);
69 public static interface ForDoAll
{
70 public void toDo(String filepath
) throws Exception
;