]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/MigrationTools/org/tianocore/migration/Common.java
Add Critic.java
[mirror_edk2.git] / Tools / Source / MigrationTools / org / tianocore / migration / Common.java
index 10bc2836d945b8199a3d9ee32dfc11fd6881721b..83b4e869b6e54b1aeb9e684305575244ce36abcb 100644 (file)
@@ -1,13 +1,11 @@
 package org.tianocore.migration;\r
 \r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileReader;\r
-import java.util.regex.Matcher;\r
-import java.util.regex.Pattern;\r
+import java.io.*;\r
+import java.util.regex.*;\r
+import java.util.*;\r
 \r
 public class Common {\r
-       public static String sourcefiletostring(String filename) throws Exception {\r
+       public static String file2string(String filename) throws Exception {\r
                BufferedReader rd = new BufferedReader(new FileReader(filename));\r
                StringBuffer wholefile = new StringBuffer();\r
                String line;\r
@@ -27,6 +25,48 @@ public class Common {
                        tempdir = new File(mtrseparate.group(1));\r
                        if (!tempdir.exists()) tempdir.mkdirs();\r
                }\r
+       }\r
+       \r
+       public static void string2file(String content, String filename) throws Exception {\r
+               ensureDir(filename);\r
+               PrintWriter outfile = new PrintWriter(new BufferedWriter(new FileWriter(filename)));\r
+               outfile.append(content);\r
+               outfile.flush();\r
+               outfile.close();\r
+       }\r
+       \r
+       public static HashSet<String> dirScan(String path) {                    // use HashSet, persue speed rather than space\r
+               HashSet<String> filelist = new HashSet<String>();\r
+               String[] list = new File(path).list();\r
+               File test;\r
+\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       test = new File(path + File.separator + list[i]);\r
+                       if (test.isDirectory()) {\r
+                               dirScan(path + File.separator + list[i]);\r
+                       } else {\r
+                               filelist.add(path + File.separator + list[i]);\r
+                       }\r
+               }\r
                \r
+               return filelist;\r
+       }\r
+       \r
+       public static void toDoAll(String path, ForDoAll fda) throws Exception { // filter of file type can be done in toDo\r
+               String[] list = new File(path).list();\r
+               File test;\r
+\r
+               for (int i = 0 ; i < list.length ; i++) {\r
+                       test = new File(path + File.separator + list[i]);\r
+                       if (test.isDirectory()) {\r
+                               toDoAll(path + File.separator + list[i], fda);\r
+                       } else {\r
+                               fda.toDo(path + File.separator + list[i]);\r
+                       }\r
+               }\r
+       }\r
+       \r
+       public static interface ForDoAll {\r
+               public void toDo(String filepath) throws Exception;\r
        }\r
 }\r