]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | \r | |
3 | The file is used to provides some useful interfaces \r | |
4 | \r | |
5 | Copyright (c) 2006, Intel Corporation\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | package org.tianocore.common;\r | |
17 | \r | |
18 | import java.io.File;\r | |
19 | import java.text.SimpleDateFormat;\r | |
20 | import java.util.Date;\r | |
21 | import java.util.UUID;\r | |
22 | \r | |
23 | /**\r | |
24 | The class is used to provides some useful interfaces \r | |
25 | \r | |
26 | @since CreateMdkPkg 1.0\r | |
27 | \r | |
28 | **/\r | |
29 | public class Tools {\r | |
30 | \r | |
31 | /**\r | |
32 | Used for test\r | |
33 | \r | |
34 | @param args\r | |
35 | \r | |
36 | **/\r | |
37 | public static void main(String[] args) {\r | |
38 | System.out.println(getCurrentDateTime());\r | |
39 | }\r | |
40 | \r | |
41 | /**\r | |
42 | Get current date and time and format it as "yyyy-MM-dd HH:mm"\r | |
43 | \r | |
44 | @return formatted current date and time\r | |
45 | \r | |
46 | **/\r | |
47 | public static String getCurrentDateTime() {\r | |
48 | Date now = new Date(System.currentTimeMillis());\r | |
49 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");\r | |
50 | return sdf.format(now);\r | |
51 | }\r | |
52 | \r | |
53 | /**\r | |
54 | Delete a folder and all its files\r | |
55 | \r | |
56 | @param fleFolderName The name of the folder which need be deleted\r | |
57 | \r | |
58 | @retval true - Delete successfully\r | |
59 | @retval false - Delete successfully\r | |
60 | \r | |
61 | **/\r | |
62 | public static boolean deleteFolder(File fleFolderName) {\r | |
63 | boolean blnIsDeleted = true;\r | |
64 | File[] aryAllFiles = fleFolderName.listFiles();\r | |
65 | \r | |
66 | for (int indexI = 0; indexI < aryAllFiles.length; indexI++) {\r | |
67 | if (blnIsDeleted) {\r | |
68 | if (aryAllFiles[indexI].isDirectory()) {\r | |
69 | //\r | |
70 | //If is a directory, recursively call this function to delete sub folders\r | |
71 | //\r | |
72 | blnIsDeleted = deleteFolder(aryAllFiles[indexI]);\r | |
73 | } else if (aryAllFiles[indexI].isFile()) {\r | |
74 | //\r | |
75 | //If is a file, delete it\r | |
76 | //\r | |
77 | if (!aryAllFiles[indexI].delete()) {\r | |
78 | blnIsDeleted = false;\r | |
79 | }\r | |
80 | }\r | |
81 | }\r | |
82 | }\r | |
83 | if (blnIsDeleted) {\r | |
84 | fleFolderName.delete();\r | |
85 | }\r | |
86 | return blnIsDeleted;\r | |
87 | }\r | |
88 | \r | |
89 | /**\r | |
90 | Generate a UUID\r | |
91 | \r | |
92 | @return the created UUID\r | |
93 | \r | |
94 | **/\r | |
95 | public static String generateUuidString() {\r | |
96 | return UUID.randomUUID().toString();\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | Get all system properties and output to the console\r | |
101 | \r | |
102 | **/\r | |
103 | public static void getSystemProperties() {\r | |
104 | System.out.println(System.getProperty("java.class.version"));\r | |
105 | System.out.println(System.getProperty("java.class.path"));\r | |
106 | System.out.println(System.getProperty("java.ext.dirs"));\r | |
107 | System.out.println(System.getProperty("os.name"));\r | |
108 | System.out.println(System.getProperty("os.arch"));\r | |
109 | System.out.println(System.getProperty("os.version"));\r | |
110 | System.out.println(System.getProperty("file.separator"));\r | |
111 | System.out.println(System.getProperty("path.separator"));\r | |
112 | System.out.println(System.getProperty("line.separator"));\r | |
113 | System.out.println(System.getProperty("user.name"));\r | |
114 | System.out.println(System.getProperty("user.home"));\r | |
115 | System.out.println(System.getProperty("user.dir"));\r | |
116 | System.out.println(System.getProperty("PATH"));\r | |
117 | \r | |
118 | System.out.println(System.getenv("PROCESSOR_REVISION"));\r | |
119 | }\r | |
120 | }\r |