
wee0.config.Env Maven / Gradle / Ivy
The newest version!
/**
* Copyright (c) 2016-2022, wee0.com.
*
* 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 wee0.config;
import java.util.function.BiConsumer;
import wee0.Wee0;
/**
* 环境变量操作对象便捷访问类
* @author baihw
* @date 2018年3月18日
**/
/**
*
* examples:
*
**/
public final class Env{
/**
* 用户未指定实现类名称时使用的默认实现类名称。
*/
public static final String DEF_IMPL_NAME = "wee0.config.local.DefaultEnv";
// 实现类实例。
private static final IEnv DEF_IMPL = ( IEnv )Wee0.getSingleInstance( IEnv.KEY_ENV_IMPL, DEF_IMPL_NAME );
/**
* 获取指定名称的环境变量。
*
* @param key 环境变量名称
* @param defVal 为空时的默认值
* @return 环境变量值
*/
public static String get( String key, String defVal ){
return DEF_IMPL.get( key, defVal );
}
/**
* 获取指定名称的环境变量(布尔类型)。
*
* @param key 环境变量名称
* @param defVal 为空时的默认值
* @return 环境变量值
*/
public static Boolean getBoolean( String key, Boolean defVal ){
return DEF_IMPL.getBoolean( key, defVal );
}
/**
* 获取指定名称的环境变量(数值类型)。
*
* @param key 环境变量名称
* @param defVal 为空时的默认值
* @return 环境变量值
*/
public static Number getNumber( String key, Number defVal ){
return DEF_IMPL.getNumber( key, defVal );
}
/**
* 遍历数据方法。
*
* @param action 遍历时的处理逻辑
*/
public static void forEach( BiConsumer action ){
DEF_IMPL.forEach( action );
}
/**
* 获取当前使用的字符集编码。
*
* @return 当前使用的字符集编码
*/
public static String getEncoding(){
return DEF_IMPL.getEncoding();
}
/**
* 获取项目工作目录。
*
* @return 项目工作目录
*/
public static String getWorkDir(){
return DEF_IMPL.getWorkDir();
}
/**
* 获取临时文件存储目录。
*
* @return 临时文件存储目录
*/
public static String getTmpDir(){
return DEF_IMPL.getTmpDir();
}
/**
* 获取系统文件存储目录。
*
* @return 系统文件存储目录
*/
public static String getSysDir(){
return DEF_IMPL.getSysDir();
}
} // end class
© 2015 - 2025 Weber Informatics LLC | Privacy Policy