首页

关于ehcache源码包中PropertyUtil属性工具类抽取常用属性类型的数据

标签:PropertyUtil,ehcache,属性工具类     发布时间:2018-04-18   

一、前言

关于ehcache的源码包中的net.sf.ehcache.util.PropertyUtil属性工具栏,对字符串属性类型间抽取转换、属性字符串转换抽取内容等。

二、源码说明

package net.sf.ehcache.util;@b@@b@import java.io.ByteArrayInputStream;@b@import java.io.IOException;@b@import java.util.Map;@b@import java.util.Properties;@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public final class PropertyUtil@b@{@b@  private static final Logger LOG = LoggerFactory.getLogger(PropertyUtil.class.getName());@b@  private static final String DEFAULT_PROPERTY_SEPARATOR = ",";@b@@b@  public static String extractAndLogProperty(String name, Properties properties)@b@  {@b@    if ((properties == null) || (properties.size() == 0))@b@      return null;@b@@b@    String foundValue = (String)properties.get(name);@b@    if (foundValue != null)@b@      foundValue = foundValue.trim();@b@@b@    if (LOG.isDebugEnabled())@b@      LOG.debug("Value found for " + name + ": " + foundValue);@b@@b@    return foundValue;@b@  }@b@@b@  public static String extractAndLogProperty(String name, Map properties)@b@  {@b@    if ((properties == null) || (properties.size() == 0))@b@      return null;@b@@b@    String foundValue = (String)properties.get(name);@b@    if (foundValue != null)@b@      foundValue = foundValue.trim();@b@@b@    if (LOG.isDebugEnabled())@b@      LOG.debug("Value found for " + name + ": " + foundValue);@b@@b@    return foundValue;@b@  }@b@@b@  public static Properties parseProperties(String propertiesString, String propertySeparator)@b@  {@b@    String propertySeparatorLocal = propertySeparator;@b@    if (propertiesString == null) {@b@      LOG.debug("propertiesString is null.");@b@      return null;@b@    }@b@    if (propertySeparator == null)@b@      propertySeparatorLocal = ",";@b@@b@    Properties properties = new Properties();@b@    String propertyLines = propertiesString.trim();@b@    propertyLines = propertyLines.replaceAll(propertySeparatorLocal, "\n");@b@    try {@b@      properties.load(new ByteArrayInputStream(propertyLines.getBytes()));@b@    } catch (IOException e) {@b@      LOG.error("Cannot load properties from " + propertiesString);@b@    }@b@    return properties;@b@  }@b@@b@  public static boolean parseBoolean(String value)@b@  {@b@    return ((value != null) && (value.equalsIgnoreCase("true")));@b@  }@b@}