Пример #1
0
 /**
  * 判断给定字串是否符合给定正则
  *
  * @param regex
  * @param str
  * @return
  */
 public static boolean testRegex(String regex, String str) {
   if (StringUtils.isEmpty(str)) {
     return false;
   }
   Pattern p = Pattern.compile(regex);
   Matcher m = p.matcher(str);
   return m.matches();
 }
Пример #2
0
 public static String urlDecode(String str) {
   if (StringUtils.isEmpty(str)) {
     return "";
   }
   try {
     return URLDecoder.decode(str, "UTF-8");
   } catch (Exception e) {
   }
   return str;
 }
Пример #3
0
  public static String toArrayString(List<String> value) {
    String tmp = "";
    for (String t : value) {
      if (StringUtils.isEmpty(t)) {
        continue;
      }

      tmp = tmp.concat("'" + t.replace("'", "").replace("\"", "").toString() + "',");
    }
    if (tmp.length() > 0) {
      tmp = tmp.substring(0, tmp.length() - 1);
    }
    return tmp;
  }
Пример #4
0
 public static List<String> toArrayString(String value) {
   if (value != null) {
     String[] tmp = value.trim().split("\\,");
     if (tmp != null && tmp.length > 0) {
       ArrayList<String> o = new ArrayList<String>();
       for (String t : tmp) {
         if (!StringUtils.isEmpty(t)) {
           o.add(t.trim());
         }
       }
       return o;
     }
   }
   return null;
 }
Пример #5
0
  /**
   * 读取资源中的字符串
   *
   * @param resource
   * @return
   * @throws IOException
   */
  public static String readFromResource(String resource) throws IOException {
    InputStream in = null;
    try {
      in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
      if (in == null) {
        in = StringUtils.class.getResourceAsStream(resource);
      }

      if (in == null) {
        return null;
      }

      String text = StringUtils.read(in);
      return text;
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (Exception e) {
        }
      }
    }
  }
Пример #6
0
 public static Double toDouble(Object value, Double defvalue) {
   if (value != null && StringUtils.isNumeric(value)) {
     return new Double(value.toString());
   }
   return defvalue;
 }
Пример #7
0
 public static Integer toInteger(Object value, Integer defvalue) {
   if (value != null && StringUtils.isNumeric(value)) {
     return new Integer(value.toString());
   }
   return defvalue;
 }
Пример #8
0
 public static Integer toInteger(String value) {
   if (value != null && StringUtils.isNumeric(value)) {
     return new Integer(value);
   }
   return null;
 }