예제 #1
0
  /**
   * 如果为0,则返回默认值
   *
   * @param originalInt
   * @param defaultInt 默认Integer
   * @return
   */
  public static Integer defaultIfError(String originalStr, Integer defaultInt) {

    try {
      return Integer.parseInt(StringUtil.trimToEmpty(originalStr));
    } catch (Exception e) {
      return defaultInt;
    }
  }
예제 #2
0
 /** 将String 转化成 Integer,如果小于等于0,将抛异常 */
 public static Integer exceptionIfSmallerThan0(String originalStr) throws Exception {
   try {
     int num = Integer.parseInt(StringUtil.trimToEmpty(originalStr));
     if (num > 0) return num;
     else throw new Exception();
   } catch (Exception e) {
     throw new Exception(originalStr + " is smaller than 0, or it is a  invalid parameter ");
   }
 }
예제 #3
0
  /**
   * Load the *.properties for config
   *
   * @throws java.io.IOException
   */
  public static Properties loadProperty() throws IOException {

    String filePathOfProperty =
        StringUtil.trimToEmpty(System.getProperty(BaseConstant.SYSTEM_PROPERTY_CONFIG_FILE_PATH));
    if (StringUtil.isBlank(filePathOfProperty)) {
      throw new FileNotFoundException(
          "Please defined,such as -DconfigFilePath=\"W:\\TaoKeeper\\taokeeper\\config\\config-test.properties\"");
    }
    return FileUtil.readPropertyFile(filePathOfProperty);
  }
예제 #4
0
 /**
  * 获取当前操作系统的语言
  *
  * @return 操作系统语言,例如zh(中文),en(英文)
  */
 public static String getOSLanguage() {
   return StringUtil.trimToEmpty(System.getProperty(USER_LANGYAGE));
 }
예제 #5
0
 /**
  * 获取当前操作系统名称
  *
  * @return 操作系统名称,例如windows xp,linux等。
  */
 public static String getOSName() {
   return StringUtil.trimToEmpty(System.getProperty(OS_NAME)).toLowerCase();
 }