]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/MigrationTools/org/tianocore/migration/Common.java
3 Copyright (c) 2006, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 package org
.tianocore
.migration
;
16 import java
.util
.regex
.*;
20 public static Pattern ptnseparate
= Pattern
.compile("(.*)\\\\([^\\\\]*)");
22 public static String
file2string(String filename
) throws Exception
{
23 BufferedReader rd
= new BufferedReader(new FileReader(filename
));
24 StringBuffer wholefile
= new StringBuffer();
26 while ((line
= rd
.readLine()) != null) {
27 wholefile
.append(line
+ "\n");
29 return wholefile
.toString();
32 public static void string2file(String content
, String filename
) throws Exception
{
34 PrintWriter outfile
= new PrintWriter(new BufferedWriter(new FileWriter(filename
)));
35 outfile
.append(content
);
40 public static void ensureDir(String objFileWhole
) {
42 Matcher mtrseparate
= ptnseparate
.matcher(objFileWhole
);
43 if (mtrseparate
.find()) {
44 tempdir
= new File(mtrseparate
.group(1));
45 if (!tempdir
.exists()) tempdir
.mkdirs();
49 public static HashSet
<String
> dirScan(String path
) { // use HashSet, persue speed rather than space
50 HashSet
<String
> filelist
= new HashSet
<String
>();
51 String
[] list
= new File(path
).list();
54 for (int i
= 0 ; i
< list
.length
; i
++) {
55 test
= new File(path
+ File
.separator
+ list
[i
]);
56 if (test
.isDirectory()) {
57 dirScan(path
+ File
.separator
+ list
[i
]);
59 filelist
.add(path
+ File
.separator
+ list
[i
]);
66 public static String
replaceAll(String line
, Pattern ptn
, String des
) {
67 Matcher mtr
= ptn
.matcher(line
);
69 return mtr
.replaceAll(des
);
74 public static String
dirCopy_(String src
) throws Exception
{
75 Matcher mtrseparate
= Common
.ptnseparate
.matcher(src
);
76 if (mtrseparate
.find()) {
77 dirCopy(src
, mtrseparate
.group(1) + File
.separator
+ "_" + mtrseparate
.group(2));
79 return mtrseparate
.group(1) + File
.separator
+ "_" + mtrseparate
.group(2);
82 public static void dirCopy(String src
, String des
) throws Exception
{
83 String
[] list
= new File(src
).list();
86 for (int i
= 0 ; i
< list
.length
; i
++) {
87 test
= new File(src
+ File
.separator
+ list
[i
]);
88 if (test
.isDirectory()) {
89 dirCopy(src
+ File
.separator
+ list
[i
], des
+ File
.separator
+ list
[i
]);
91 ensureDir(des
+ File
.separator
+ list
[i
]);
92 string2file(file2string(src
+ File
.separator
+ list
[i
]), des
+ File
.separator
+ list
[i
]);
97 public static void toDoAll(String path
, ForDoAll fda
) throws Exception
{ // filter of file type can be done in toDo
98 String
[] list
= new File(path
).list();
101 for (int i
= 0 ; i
< list
.length
; i
++) {
102 test
= new File(path
+ File
.separator
+ list
[i
]);
103 if (test
.isDirectory()) {
104 toDoAll(path
+ File
.separator
+ list
[i
], fda
);
106 fda
.toDo(path
+ File
.separator
+ list
[i
]);
111 public static interface ForDoAll
{
112 public void toDo(String filepath
) throws Exception
;