]>
Commit | Line | Data |
---|---|---|
878ddf1f | 1 | /** @file\r |
2 | Java class Tools contains common use procedures.\r | |
3 | \r | |
4 | Copyright (c) 2006, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | **/\r | |
13 | package org.tianocore.common;\r | |
14 | \r | |
15 | import java.io.File;\r | |
16 | import java.text.SimpleDateFormat;\r | |
17 | import java.util.Calendar;\r | |
18 | import java.util.Date;\r | |
19 | import java.util.UUID;\r | |
20 | \r | |
21 | /**\r | |
22 | This class contains static methods for some common operations\r | |
23 | \r | |
24 | @since PackageEditor 1.0\r | |
25 | **/\r | |
26 | public class Tools {\r | |
27 | \r | |
28 | /**\r | |
29 | get current date and time, then return\r | |
30 | @return String\r | |
31 | **/\r | |
32 | public static String getCurrentDateTime() {\r | |
33 | Date now = new Date(System.currentTimeMillis());\r | |
34 | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");\r | |
35 | return sdf.format(now);\r | |
36 | }\r | |
37 | \r | |
38 | /**\r | |
39 | Delete a folder and all its files\r | |
40 | @param strFolderName\r | |
41 | @return boolean\r | |
42 | **/\r | |
43 | public static boolean deleteFolder(File fleFolderName) {\r | |
44 | boolean blnIsDeleted = true;\r | |
45 | File[] aryAllFiles = fleFolderName.listFiles();\r | |
46 | \r | |
47 | for (int indexI = 0; indexI < aryAllFiles.length; indexI++) {\r | |
48 | if (blnIsDeleted) {\r | |
49 | if (aryAllFiles[indexI].isDirectory()) {\r | |
50 | blnIsDeleted = deleteFolder(aryAllFiles[indexI]);\r | |
51 | } else if (aryAllFiles[indexI].isFile()) {\r | |
52 | if (!aryAllFiles[indexI].delete()) {\r | |
53 | blnIsDeleted = false;\r | |
54 | }\r | |
55 | }\r | |
56 | }\r | |
57 | }\r | |
58 | if (blnIsDeleted) {\r | |
59 | fleFolderName.delete();\r | |
60 | }\r | |
61 | return blnIsDeleted;\r | |
62 | }\r | |
63 | \r | |
64 | /**\r | |
65 | Get a new GUID\r | |
66 | \r | |
67 | @return String\r | |
68 | **/\r | |
69 | public static String generateUuidString() {\r | |
70 | return UUID.randomUUID().toString();\r | |
71 | }\r | |
72 | \r | |
73 | }\r |