Java tutorial
package com.jiangyifen.ec2.servlet.http.common.utils; import java.io.InputStream; import java.util.HashSet; import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * @Description ?????? * * @author JRH * @date 201487 ?6:10:52 */ public class AnalyzeIfaceJointUtil { public static String IP_FILTERABLE = "ip_filterable"; // ? public static String AUTHORIZE_IPS = "authorize_ips"; // ??EC2 ?IP public static String JOINT_LICENSE_NECESSARY = "joint_license_necessary"; // EC2???License ??accessId accessKey ? public static String PAUSE_LOG_CREATEABLE = "pause_log_createable"; // ? //other config private static Logger logger; public static Properties props = null; public static InputStream inputStream = null; public static HashSet<String> AUTHORIZE_IPS_SET = new HashSet<String>(); // ?EC2?ip? public static boolean PAUSE_LOG_CREATEABLE_VALUE = true; // public static boolean JOINT_LICENSE_NECESSARY_VALUE = true; // IP public static boolean IP_FILTERABLE_VALUE = true; // IP static { try { logger = LoggerFactory.getLogger(AnalyzeIfaceJointUtil.class); props = new Properties(); inputStream = AnalyzeIfaceJointUtil.class.getClassLoader() .getResourceAsStream("com/jiangyifen/ec2/servlet/http/common/utils/iface_joint.properties"); props.load(inputStream); String ip_filterable_str = AnalyzeIfaceJointUtil.props.getProperty(IP_FILTERABLE); if ("true".equals(ip_filterable_str)) { IP_FILTERABLE_VALUE = true; } else { IP_FILTERABLE_VALUE = false; } String authorize_ips_str = AnalyzeIfaceJointUtil.props.getProperty(AUTHORIZE_IPS); if (authorize_ips_str != null && !"".equals(authorize_ips_str)) { for (String ip : authorize_ips_str.split(",")) { ip = ip.replace(" ", ""); // if (!"".equals(ip)) { AUTHORIZE_IPS_SET.add(ip); } } } String joint_license_necessary_str = AnalyzeIfaceJointUtil.props.getProperty(JOINT_LICENSE_NECESSARY); if ("true".equals(joint_license_necessary_str)) { JOINT_LICENSE_NECESSARY_VALUE = true; } else { JOINT_LICENSE_NECESSARY_VALUE = false; } String pause_log_createable_str = AnalyzeIfaceJointUtil.props.getProperty(PAUSE_LOG_CREATEABLE); if ("true".equals(pause_log_createable_str)) { PAUSE_LOG_CREATEABLE_VALUE = true; } else { PAUSE_LOG_CREATEABLE_VALUE = false; } } catch (Exception e) { logger.error("Can't find or can't read the configuration which for system butt joint!", e); } } /** * @Description ????EC2?ip? * * @author JRH * @date 201487 ?7:15:10 * @return HashSet<String> */ public static HashSet<String> getAuthorizeIps() { HashSet<String> authorizeIpsSet = new HashSet<String>(); String authorize_ips_str = props.getProperty(AUTHORIZE_IPS); if (authorize_ips_str != null && !"".equals(authorize_ips_str)) { for (String ip : authorize_ips_str.split(",")) { authorizeIpsSet.add(ip); } } return authorizeIpsSet; } // TODO public static void main(String[] args) { // System.out.println(props.getProperty(AUTHORIZE_IPS)); // System.out.println(props.getProperty(PAUSE_LOG_CREATEABLE)); System.out.println(IP_FILTERABLE_VALUE); System.out.println("-----" + StringUtils.join(AUTHORIZE_IPS_SET, ",")); System.out.println(JOINT_LICENSE_NECESSARY_VALUE); System.out.println(PAUSE_LOG_CREATEABLE_VALUE); } }