All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.feilong.core.lang.SystemUtil Maven / Gradle / Ivy

Go to download

feilong is a suite of core and expanded libraries that include utility classes, http, excel,cvs, io classes, and much much more.

There is a newer version: 4.0.8
Show newest version
/*
 * Copyright (C) 2008 feilong
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feilong.core.lang;

import static com.feilong.core.bean.ConvertUtil.toMap;
import static com.feilong.core.util.SortUtil.sortMapByKeyAsc;

import java.util.Map;
import java.util.Properties;

import com.feilong.core.Validate;
import com.feilong.core.bean.ConvertUtil;

/**
 * {@link java.lang.System}工具类.
 * 
 * 

常用Properties:

* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
字段说明
file.encoding
* {@link "org.apache.commons.lang3.SystemUtils#FILE_ENCODING"}
utf-8
file.separator
* {@link "org.apache.commons.lang3.SystemUtils#FILE_SEPARATOR"}
\\
java.home
* {@link "org.apache.commons.lang3.SystemUtils#JAVA_HOME"}
D:\\Program Files\\Java\\jdk1.6.0_37\\jre
java.io.tmpdir
* {@link "org.apache.commons.lang3.SystemUtils#JAVA_IO_TMPDIR"}
C:\\Users\\feilong\\AppData\\Local\\Temp\\
java.version
* {@link "org.apache.commons.lang3.SystemUtils#JAVA_VERSION"}
1.6.0_37
line.separator
* {@link System#lineSeparator()}
\r\n
user.dir
* {@link "org.apache.commons.lang3.SystemUtils#USER_DIR"}
E:\\Workspaces\\feilong\\feilong-platform\\commons\\feilong-core
user.home
* {@link "org.apache.commons.lang3.SystemUtils#USER_HOME"}
C:\\Users\\feilong
*
* * *

其他Properties:

* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
字段说明
awt.toolkitsun.awt.windows.WToolkit
file.encoding.pkgsun.io
java.awt.graphicsenvsun.awt.Win32GraphicsEnvironment
java.awt.printerjobsun.awt.windows.WPrinterJob
java.class.pathE:\\Workspaces\\feilong\\feilong-platform\\commons\\feilong-core\\target\\test-classes;E:\\Workspaces\\feilong\\feilong-platform\\ * commons\\feilong-core\\target\\classes;D:\\FeiLong * Soft\\Essential\\Development\\repository\\org\\slf4j\\slf4j-api\\1.7.6\\slf4j-api-1.7.6.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\net\\sf\\json-lib\\json-lib\\2.4\\json-lib-2.4-jdk15.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\net\\sf\\ezmorph\\ezmorph\\1.0.6\\ezmorph-1.0.6.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\commons-lang\\commons-lang\\2.6\\commons-lang-2.6.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\org\\apache\\commons\\commons-lang3\\3.3.2\\commons-lang3-3.3.2.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\commons-beanutils\\commons-beanutils\\1.9.1\\commons-beanutils-1.9.1.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\commons-logging\\commons-logging\\1.1.1\\commons-logging-1.1.1.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\commons-collections\\commons-collections\\3.2.1\\commons-collections-3.2.1.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\xom\\xom\\1.2.5\\xom-1.2.5.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\xml-apis\\xml-apis\\1.3.03\\xml-apis-1.3.03.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\xerces\\xercesImpl\\2.8.0\\xercesImpl-2.8.0.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\xalan\\xalan\\2.7.0\\xalan-2.7.0.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\junit\\junit\\4.10\\junit-4.10.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\org\\hamcrest\\hamcrest-core\\1.1\\hamcrest-core-1.1.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\org\\easymock\\easymock\\3.1\\easymock-3.1.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\cglib\\cglib-nodep\\2.2.2\\cglib-nodep-2.2.2.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository * \\org\\objenesis\\objenesis\\1.2\\objenesis-1.2.jar;E:\\Workspaces\\feilong\\else\\feilong-common-test\\target\\classes;D:\\FeiLong * Soft\\Essential\\Development\\repository\\org\\slf4j\\slf4j-log4j12\\1.7.6\\slf4j-log4j12-1.7.6.jar;D:\\FeiLong * Soft\\Essential\\Development\\repository\\log4j\\log4j\\1.2.17\\log4j-1.2.17.jar;/D:/FeiLong * Soft/Essential/Development/eclipse-jee-kepler-SR2-win32/configuration/org.eclipse.osgi/bundles/378/1/.cp/;/D:/FeiLong * Soft/Essential/Development/eclipse-jee-kepler-SR2-win32/configuration/org.eclipse.osgi/bundles/377/1/.cp/
java.class.version50.0
java.endorsed.dirsD:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\endorsed
java.ext.dirsD:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\ext;C:\\Windows\\Sun\\Java\\lib\\ext
java.library.pathD:\\Program Files\\Java\\jdk1.6.0_37\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;C:\\Windows;D:/Program * Files/Java/jre6/bin/client;D:/Program Files/Java/jre6/bin;D:/Program Files/Java/jre6/lib/i386;C:\\Program Files (x86)\\NVIDIA * Corporation\\PhysX\\Common;C:\\Windows\\system32;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files * (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program * Files\\TortoiseSVN\\bin;.
java.runtime.nameJava(TM) SE Runtime Environment
java.runtime.version1.6.0_37-b06
java.specification.nameJava Platform API Specification
java.specification.vendorSun Microsystems Inc.
java.specification.version1.6
java.vendorSun Microsystems Inc.
java.vendor.urlhttp://java.sun.com/
java.vendor.url.bughttp://java.sun.com/cgi-bin/bugreport.cgi
java.vm.infomixed mode
java.vm.nameJava HotSpot(TM) Client VM
java.vm.specification.nameJava Virtual Machine Specification
java.vm.specification.vendorSun Microsystems Inc.
java.vm.specification.version1.0
java.vm.vendorSun Microsystems Inc.
java.vm.version20.12-b01
os.archx86
os.nameWindows 7
os.version6.1
path.separator;
sun.arch.data.model32
sun.boot.class.pathD:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\resources.jar;D:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\rt.jar;D:\\Program * Files\\Java\\jdk1.6.0_37\\jre\\lib\\sunrsasign.jar;D:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\jsse.jar;D:\\Program * Files\\Java\\jdk1.6.0_37\\jre\\lib\\jce.jar;D:\\Program Files\\Java\\jdk1.6.0_37\\jre\\lib\\charsets.jar;D:\\Program * Files\\Java\\jdk1.6.0_37\\jre\\lib\\modules\\jdk.boot.jar;D:\\Program Files\\Java\\jdk1.6.0_37\\jre\\classes
sun.boot.library.pathD:\\Program Files\\Java\\jdk1.6.0_37\\jre\\bin
sun.cpu.endianlittle
sun.cpu.isalistpentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
sun.desktopwindows
sun.io.unicode.encodingUnicodeLittle
sun.java.commandorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner -version 3 -port 60401 -testLoaderClass * org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader -loaderpluginname org.eclipse.jdt.junit4.runtime -test * com.feilong.core.lang.SystemUtilTest:getPropertiesMapForLog
sun.java.launcherSUN_STANDARD
sun.jnu.encodingGBK
sun.management.compilerHotSpot Client Compiler
sun.os.patch.levelService Pack 1
user.countryCN
user.languagezh
user.namefeilong
user.timezoneAsia/Bangkok
*
* * @author feilong * @see java.lang.System * @see "org.apache.commons.lang3.SystemUtils#USER_HOME" * @see "org.apache.commons.lang3.SystemUtils#FILE_ENCODING" * @see "org.apache.commons.lang3.SystemUtils#FILE_SEPARATOR" * @see "org.apache.commons.lang3.SystemUtils#JAVA_IO_TMPDIR" * * @see "org.springframework.util.SystemPropertyUtils" * @since 1.0.7 */ public final class SystemUtil{ /** * The System property key for the user home directory. * * @since 3.0.0 */ private static final String USER_HOME_KEY = "user.home"; /** * The {@code user.home} System Property. User's home directory. * *

* Defaults to {@code null} if the runtime does not have security access to read this property or the property does * not exist. *

* *

* This value is initialized when the class is loaded. If {@link System#setProperty(String,String)} or * {@link System#setProperties(java.util.Properties)} is called after this class is loaded, the value will be out of * sync with that System property. *

* * @since Java 1.1 * @since 3.0.0 */ public static final String USER_HOME = getSystemProperty(USER_HOME_KEY); /** Don't let anyone instantiate this class. */ private SystemUtil(){ //AssertionError不是必须的. 但它可以避免不小心在类的内部调用构造器. 保证该类在任何情况下都不会被实例化. //see 《Effective Java》 2nd throw new AssertionError("No " + getClass().getName() + " instances for you!"); } // ----------------------------------------------------------------------- /** *

* Gets a System property, defaulting to {@code null} if the property cannot be read. *

*

* If a {@code SecurityException} is caught, the return value is {@code null} and a message is written to * {@code System.err}. *

* * @param property * the system property name * @return the system property value or {@code null} if a security problem occurs * @since 3.0.0 */ private static String getSystemProperty(final String property){ try{ return System.getProperty(property); }catch (final SecurityException ex){ // we are not allowed to look at this property return null; } } //--------------------------------------------------------------- /** * 取到 {@link System#getProperty(String)},转成 {@link java.util.TreeMap},以遍输出log的时候,会顺序显示. * *

示例:

* *
* *
     * LOGGER.debug(JsonUtil.format(SystemUtil.getPropertiesMap()));
     * 
* * 返回: * *
     * {
        "file.encoding": "UTF-8",
        "file.encoding.pkg": "sun.io",
        "file.separator": "\\",
        "java.class.path": "E:\\Workspaces\\feilong\\feilong-core\\target\\test-classes;E:\\Workspaces\\feilong\\feilong-core\\target\\classes;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\apache\\commons\\commons-lang3\\3.4\\commons-lang3-3.4.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\apache\\commons\\commons-collections4\\4.1\\commons-collections4-4.1.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\commons-beanutils\\commons-beanutils\\1.9.2\\commons-beanutils-1.9.2.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\net\\sf\\json-lib\\json-lib\\2.4\\json-lib-2.4-jdk15.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\net\\sf\\ezmorph\\ezmorph\\1.0.6\\ezmorph-1.0.6.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\slf4j\\slf4j-log4j12\\1.7.21\\slf4j-log4j12-1.7.21.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\log4j\\log4j\\1.2.17\\log4j-1.2.17.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\commons-lang\\commons-lang\\2.6\\commons-lang-2.6.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\commons-logging\\commons-logging\\1.2\\commons-logging-1.2.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\commons-collections\\commons-collections\\3.2.2\\commons-collections-3.2.2.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\hamcrest\\hamcrest-library\\1.3\\hamcrest-library-1.3.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\hamcrest\\hamcrest-core\\1.3\\hamcrest-core-1.3.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\xom\\xom\\1.2.5\\xom-1.2.5.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\xalan\\xalan\\2.7.0\\xalan-2.7.0.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\org\\slf4j\\slf4j-api\\1.7.21\\slf4j-api-1.7.21.jar;D:\\FeiLong Soft\\Essential\\Development\\repository\\junit\\junit\\4.12\\junit-4.12.jar;E:\\Workspaces\\feilong\\feilong-resource\\feilong-common-test\\target\\classes;/D:/FeiLong Soft/Essential/Development/eclipse-jee-mars-2-win32/configuration/org.eclipse.osgi/425/0/.cp/;/D:/FeiLong Soft/Essential/Development/eclipse-jee-mars-2-win32/configuration/org.eclipse.osgi/424/0/.cp/",
        "java.class.version": "51.0",
        "java.endorsed.dirs": "D:\\Program Files\\Java\\jdk1.7.0_60\\jre\\lib\\endorsed",
        "java.ext.dirs": "D:\\Program Files\\Java\\jdk1.7.0_60\\jre\\lib\\ext;C:\\Windows\\Sun\\Java\\lib\\ext",
        "java.home": "D:\\Program Files\\Java\\jdk1.7.0_60\\jre",
        "java.io.tmpdir": "C:\\Users\\feilong\\AppData\\Local\\Temp\\",
        "java.library.path": "D:\\Program Files\\Java\\jdk1.7.0_60\\bin;C:\\Windows\\Sun\\Java\\bin;C:\\Windows\\system32;C:\\Windows;D:/Program Files/Java/jre1.8.0_45/bin/client;D:/Program Files/Java/jre1.8.0_45/bin;D:/Program Files/Java/jre1.8.0_45/lib/i386;C:\\ProgramData\\Oracle\\Java\\javapath;D:\\Goto;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Common Files\\NetSarang;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files\\TortoiseGit\\bin;D:\\Program Files\\Java\\jdk1.8.0_45\\bin;D:\\FeiLong Soft;D:\\FeiLong Soft\\Essential\\run;D:\\FeiLong Soft\\StaticDevelopment\\apache-ant-1.9.3\\bin;D:\\FeiLong Soft\\StaticDevelopment\\apache-maven-3.3.3\\bin;D:\\FeiLong Soft\\Datebase\\postgresql\\postgresql-9.4.0-1-windows-x64-binaries\\bin;C:\\Program Files (x86)\\Git\\bin;C:\\Program Files (x86)\\Git\\libexec\\git-core;D:\\FeiLong Soft\\Essential\\Development\\redis-2.8.19;D:\\FeiLong Soft\\Essential\\Development\\eclipse-jee-mars-2-win32;;.",
        "java.runtime.name": "Java(TM) SE Runtime Environment",
        "java.runtime.version": "1.7.0_60-b19",
        "java.specification.name": "Java Platform API Specification",
        "java.specification.vendor": "Oracle Corporation",
        "java.specification.version": "1.7",
        "java.vendor": "Oracle Corporation",
        "java.vendor.url": "http://java.oracle.com/",
        "java.vendor.url.bug": "http://bugreport.sun.com/bugreport/",
        "java.version": "1.7.0_60",
        "java.vm.info": "mixed mode, sharing",
        "java.vm.name": "Java HotSpot(TM) Client VM",
        "java.vm.specification.name": "Java Virtual Machine Specification",
        "java.vm.specification.vendor": "Oracle Corporation",
        "java.vm.specification.version": "1.7",
        "java.vm.vendor": "Oracle Corporation",
        "java.vm.version": "24.60-b09",
        "line.separator": "\r\n",
        "os.arch": "x86",
        "os.name": "Windows 7",
        "os.version": "6.1",
        "path.separator": ";",
        "sun.desktop": "windows",
        "user.country": "CN",
        "user.dir": "E:\\Workspaces\\feilong\\feilong-core",
        "user.home": "C:\\Users\\feilong",
        "user.language": "zh",
        "user.name": "feilong",
        "user.script": "",
        "user.timezone": "Asia/Shanghai",
        "user.variant": ""
    }
     * 
     * 
* *
* * @return the properties map for log * @see System#getProperties() * @see ConvertUtil#toMap(Properties) * @see "org.springframework.core.env.AbstractEnvironment#getSystemProperties()" * @since 1.8.0 change name */ public static Map getPropertiesMap(){ return toMap(System.getProperties()); } /** * 取到 {@link System#getenv()},转成 {@link java.util.TreeMap},以遍输出log的时候,会顺序显示. * *

示例:

* *
* *
     * 
     * LOGGER.debug(JsonUtil.format(SystemUtil.getEnvMap()));
     * 
     * 
* * 返回: * *
     * {
        "=::": "::\\",
        "ALLUSERSPROFILE": "C:\\ProgramData",
        "ANT_HOME": "D:\\FeiLong Soft\\StaticDevelopment\\apache-ant-1.9.3",
        "APPDATA": "C:\\Users\\feilong\\AppData\\Roaming",
        "APP_ENCRYPTION_PASSWORD_SPEEDO": "speedodev",
        "COMPUTERNAME": "FEILONG-PC",
        "ComSpec": "C:\\Windows\\system32\\cmd.exe",
        "FP_NO_HOST_CHECK": "NO",
        "HOME": "C:\\Users\\feilong",
        "HOMEDRIVE": "C:",
        "HOMEPATH": "\\Users\\feilong",
        "LOCALAPPDATA": "C:\\Users\\feilong\\AppData\\Local",
        "LOGONSERVER": "\\\\FEILONG-PC",
        "NUMBER_OF_PROCESSORS": "4",
        "OS": "Windows_NT",
        "PATHEXT": ".COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC",
        "PROCESSOR_ARCHITECTURE": "x86",
        "PROCESSOR_ARCHITEW6432": "AMD64",
        "PROCESSOR_LEVEL": "6",
        "PROCESSOR_REVISION": "3a09",
        "PSModulePath": "C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\",
        "PUBLIC": "C:\\Users\\Public",
        "Path": "D:/Program Files/Java/jre1.8.0_45/bin/client;D:/Program Files/Java/jre1.8.0_45/bin;D:/Program Files/Java/jre1.8.0_45/lib/i386;C:\\ProgramData\\Oracle\\Java\\javapath;D:\\Goto;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files (x86)\\Common Files\\NetSarang;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x86;C:\\Program Files (x86)\\Intel\\OpenCL SDK\\2.0\\bin\\x64;C:\\Program Files (x86)\\ATI Technologies\\ATI.ACE\\Core-Static;C:\\Program Files\\TortoiseSVN\\bin;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files\\TortoiseGit\\bin;D:\\Program Files\\Java\\jdk1.8.0_45\\bin;D:\\FeiLong Soft;D:\\FeiLong Soft\\Essential\\run;D:\\FeiLong Soft\\StaticDevelopment\\apache-ant-1.9.3\\bin;D:\\FeiLong Soft\\StaticDevelopment\\apache-maven-3.3.3\\bin;D:\\FeiLong Soft\\Datebase\\postgresql\\postgresql-9.4.0-1-windows-x64-binaries\\bin;C:\\Program Files (x86)\\Git\\bin;C:\\Program Files (x86)\\Git\\libexec\\git-core;D:\\FeiLong Soft\\Essential\\Development\\redis-2.8.19;D:\\FeiLong Soft\\Essential\\Development\\eclipse-jee-mars-2-win32;",
        "ProgramData": "C:\\ProgramData",
        "ProgramFiles": "C:\\Program Files (x86)",
        "ProgramFiles(x86)": "C:\\Program Files (x86)",
        "SESSIONNAME": "Console",
        "SystemDrive": "C:",
        "SystemRoot": "C:\\Windows",
        "TEMP": "C:\\Users\\feilong\\AppData\\Local\\Temp",
        "TMP": "C:\\Users\\feilong\\AppData\\Local\\Temp",
        "USERDOMAIN": "feilong-PC",
        "USERNAME": "feilong",
        "USERPROFILE": "C:\\Users\\feilong",
        "windir": "C:\\Windows",
        "windows_tracing_flags": "3",
        "windows_tracing_logfile": "C:\\BVTBin\\Tests\\installpackage\\csilogfile.log"
    }
     * 
     * 
* *
* * @return the env map for log * @see System#getenv() * @see "org.springframework.core.env.AbstractEnvironment#getSystemEnvironment()" * @since 1.8.0 change name */ public static Map getEnvMap(){ return sortMapByKeyAsc(System.getenv()); } //--------------------------------------------------------------- /** * 循环 map ,设置到系统属性 {@link java.lang.System#setProperty(String, String)}. * *

* 如果 map 是null,抛出 {@link NullPointerException}
* 如果 map 是empty,抛出 {@link IllegalArgumentException}
*

* * @param map * the properties from map * @see java.lang.System#setProperty(String, String) * @since 1.2.0 */ public static void setPropertiesFromMap(Map map){ Validate.notEmpty(map, "map can't be null/empty!"); for (Map.Entry entry : map.entrySet()){ System.setProperty(entry.getKey(), entry.getValue()); } } /** * 设置 properties from properties. * *

* 如果 properties 是null,抛出 {@link NullPointerException}
*

* * @param properties * the properties from properties * @see ConvertUtil#toMap(Properties) * @see #setPropertiesFromMap(Map) * @see java.lang.System#setProperties(Properties) * @since 1.2.0 */ public static void setPropertiesFromProperties(Properties properties){ Validate.notNull(properties, "properties can't be null!"); setPropertiesFromMap(toMap(properties)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy