]>
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 ensureDir(String objFileWhole
) {
34 Matcher mtrseparate
= ptnseparate
.matcher(objFileWhole
);
35 if (mtrseparate
.find()) {
36 tempdir
= new File(mtrseparate
.group(1));
37 if (!tempdir
.exists()) tempdir
.mkdirs();
41 public static void string2file(String content
, String filename
) throws Exception
{
43 PrintWriter outfile
= new PrintWriter(new BufferedWriter(new FileWriter(filename
)));
44 outfile
.append(content
);
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
dirCopy_(String src
) throws Exception
{
67 Matcher mtrseparate
= Common
.ptnseparate
.matcher(src
);
68 if (mtrseparate
.find()) {
69 dirCopy(src
, mtrseparate
.group(1) + File
.separator
+ "_" + mtrseparate
.group(2));
71 return mtrseparate
.group(1) + File
.separator
+ "_" + mtrseparate
.group(2);
74 public static void dirCopy(String src
, String des
) throws Exception
{
75 String
[] list
= new File(src
).list();
78 for (int i
= 0 ; i
< list
.length
; i
++) {
79 test
= new File(src
+ File
.separator
+ list
[i
]);
80 if (test
.isDirectory()) {
81 dirCopy(src
+ File
.separator
+ list
[i
], des
+ File
.separator
+ list
[i
]);
83 ensureDir(des
+ File
.separator
+ list
[i
]);
84 string2file(file2string(src
+ File
.separator
+ list
[i
]), des
+ File
.separator
+ list
[i
]);
89 public static void toDoAll(String path
, ForDoAll fda
) throws Exception
{ // filter of file type can be done in toDo
90 String
[] list
= new File(path
).list();
93 for (int i
= 0 ; i
< list
.length
; i
++) {
94 test
= new File(path
+ File
.separator
+ list
[i
]);
95 if (test
.isDirectory()) {
96 toDoAll(path
+ File
.separator
+ list
[i
], fda
);
98 fda
.toDo(path
+ File
.separator
+ list
[i
]);
103 public static interface ForDoAll
{
104 public void toDo(String filepath
) throws Exception
;