+++ /dev/null
-/** @file\r
- \r
- The file is used to provides some useful interfaces \r
- \r
- Copyright (c) 2006, Intel Corporation\r
- All rights reserved. This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
- \r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
- \r
- **/\r
-\r
-package org.tianocore.common;\r
-\r
-import java.io.File;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Date;\r
-import java.util.UUID;\r
-\r
-/**\r
- The class is used to provides some useful interfaces \r
- \r
- @since ModuleEditor 1.0\r
- \r
- **/\r
-public class Tools {\r
-\r
- /**\r
- Used for test\r
- \r
- @param args\r
- \r
- **/\r
- public static void main(String[] args) {\r
- System.out.println(getCurrentDateTime());\r
- }\r
-\r
- /**\r
- Get current date and time and format it as "yyyy-MM-dd HH:mm"\r
- \r
- @return formatted current date and time\r
- \r
- **/\r
- public static String getCurrentDateTime() {\r
- Date now = new Date(System.currentTimeMillis());\r
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");\r
- return sdf.format(now);\r
- }\r
-\r
- /**\r
- Delete a folder and all its files\r
- \r
- @param fleFolderName The name of the folder which need be deleted\r
- \r
- @retval true - Delete successfully\r
- @retval false - Delete successfully\r
- \r
- **/\r
- public static boolean deleteFolder(File fleFolderName) {\r
- boolean blnIsDeleted = true;\r
- File[] aryAllFiles = fleFolderName.listFiles();\r
-\r
- for (int indexI = 0; indexI < aryAllFiles.length; indexI++) {\r
- if (blnIsDeleted) {\r
- if (aryAllFiles[indexI].isDirectory()) {\r
- //\r
- //If is a directory, recursively call this function to delete sub folders\r
- //\r
- blnIsDeleted = deleteFolder(aryAllFiles[indexI]);\r
- } else if (aryAllFiles[indexI].isFile()) {\r
- //\r
- //If is a file, delete it\r
- //\r
- if (!aryAllFiles[indexI].delete()) {\r
- blnIsDeleted = false;\r
- }\r
- }\r
- }\r
- }\r
- if (blnIsDeleted) {\r
- fleFolderName.delete();\r
- }\r
- return blnIsDeleted;\r
- }\r
-\r
- /**\r
- Generate a UUID\r
- \r
- @return the created UUID\r
- \r
- **/\r
- public static String generateUuidString() {\r
- return UUID.randomUUID().toString();\r
- }\r
-\r
- /**\r
- Get all system properties and output to the console\r
- \r
- **/\r
- public static void getSystemProperties() {\r
- System.out.println(System.getProperty("java.class.version"));\r
- System.out.println(System.getProperty("java.class.path"));\r
- System.out.println(System.getProperty("java.ext.dirs"));\r
- System.out.println(System.getProperty("os.name"));\r
- System.out.println(System.getProperty("os.arch"));\r
- System.out.println(System.getProperty("os.version"));\r
- System.out.println(System.getProperty("file.separator"));\r
- System.out.println(System.getProperty("path.separator"));\r
- System.out.println(System.getProperty("line.separator"));\r
- System.out.println(System.getProperty("user.name"));\r
- System.out.println(System.getProperty("user.home"));\r
- System.out.println(System.getProperty("user.dir"));\r
- System.out.println(System.getProperty("PATH"));\r
-\r
- System.out.println(System.getenv("PROCESSOR_REVISION"));\r
- }\r
-}\r