类 General

java.lang.Object
com.sh.javax.util.General

public final class General extends Object

Description: 通用函数类,包括一系列有用的函数,其中大部分是静态函数。

Title:首亨软件 - CRM

  • 字段详细资料

    • classPath

      public static String classPath
    • AUTH_ERROR_MESSAGE

      protected static String AUTH_ERROR_MESSAGE
    • sysParam

      public static Properties sysParam
    • sysParamEx

      public static Properties sysParamEx
    • licenseRangMillis

      protected static long licenseRangMillis
  • 构造器详细资料

    • General

      public General()
  • 方法详细资料

    • getMachineCode

      public static String getMachineCode()
    • convertWideString

      public static String convertWideString(String str)
      替换中文字符
      参数:
      str - String
      返回:
      String
    • getLicenseByMachineCode

      public static String getLicenseByMachineCode(String machineCode)
    • getLicenseByMachineCodeLocal

      public static String getLicenseByMachineCodeLocal(String machineCode)
      64位系统使用
      参数:
      machineCode - String
      返回:
      String
    • getMaxOnlineUser

      public static int getMaxOnlineUser()
      获取系统允许的最大在线用户数
      返回:
      int
    • convertISOToGBK

      public static String convertISOToGBK(String str)
      将ISO编码格式的字符串转换成GBK编码字符串
      参数:
      str - 用ISO编码的字符串
      返回:
      GBK编码的字符串
    • convertISOToUTF8

      public static String convertISOToUTF8(String str)
    • convertGBKToISO

      public static String convertGBKToISO(String str)
      将GBK编码格式的字符串转换成ISO编码字符串
      参数:
      str - 用GBK编码的字符串
      返回:
      ISO编码的字符串
    • convertStringToDate

      public static Date convertStringToDate(String str) throws ParseException
      将"yyyy年M月d日"格式的字符串转化成日期
      参数:
      str - 日期字符串
      返回:
      日期对象
      抛出:
      ParseException - ParseException
    • convertStringToDate

      public static Date convertStringToDate(String str, String pattern) throws ParseException
      将特定格式的字符串转化成日期
      参数:
      str - 日期字符串
      pattern - 字符串模式,如:yyyy年M月d日,yyyy-MM-dd等
      返回:
      日期对象
      抛出:
      ParseException - ParseException
    • convertDateToString

      public static String convertDateToString(Date date)
      将日期转化成字符串,日期的模式为"yyyy年MM月dd日"
      参数:
      date - 日期对象
      返回:
      表示日期的字符串
    • convertDateToString

      public static String convertDateToString(Date date, String pattern)
      将日期对象转换成特定模式的字符串
      参数:
      date - 日期对象
      pattern - 字符串模式,如:yyyy年M月d日,yyyy-MM-dd等
      返回:
      特定格式的字符串
    • convertDateToString

      public static String convertDateToString(Date date, String pattern, String toZoneId)
      将日期对象转换成特定模式的字符串
      参数:
      date - 日期对象
      pattern - 字符串模式,如:yyyy年M月d日,yyyy-MM-dd等
      toZoneId - 时区
      返回:
      特定格式的字符串
    • convertStringToInt

      public static int convertStringToInt(String str)
      将字符串转换成int值
      参数:
      str - 字符串
      返回:
      对应的int值
    • convertStringToShort

      public static short convertStringToShort(String str)
      将字符串转换成short值
      参数:
      str - 字符串
      返回:
      对应的int值
    • convertStringToLong

      public static long convertStringToLong(String str)
      将字符串转换成long值
      参数:
      str - 字符串
      返回:
      对应的int值
    • convertStringToFloat

      public static float convertStringToFloat(String str)
      将字符串转换成float值
      参数:
      str - 字符串
      返回:
      对应的float值
    • convertStringToDouble

      public static double convertStringToDouble(String str)
      将字符串转换成double值
      参数:
      str - 字符串
      返回:
      对应的double值
    • convertDateToSqlDate

      public static Date convertDateToSqlDate(Date date)
      将java.util.Data类型转化成java.sql.Data
      参数:
      date - java.util.Data对象
      返回:
      java.sql.Data对象
    • convertSqlDateToDate

      public static Date convertSqlDateToDate(Date date)
    • convertDateToTimestamp

      public static Timestamp convertDateToTimestamp(Date date)
      将java.util.Data类型转化成java.sql.Timestamp
      参数:
      date - java.util.Data对象
      返回:
      java.sql.Timestamp对象
    • convertStringToTimestamp

      public static Timestamp convertStringToTimestamp(String str) throws Exception
      抛出:
      Exception
    • convertStringToTimestamp

      public static Timestamp convertStringToTimestamp(String str, String pattern) throws Exception
      抛出:
      Exception
    • toJson

      public static final String toJson(Object paramObject)
    • split

      public static String[] split(String str)
      将一个以逗号隔开的字符串转化成字符串数组
      参数:
      str - String 以逗号隔开的字符串
      返回:
      String[] 字符串数组
    • split

      public static String[] split(String str, String delim)
      将用指定符号格开的字符串转化成字符串数组
      参数:
      str - 带有指定符号的字符串
      delim - 指定符号
      返回:
      对应的字符串数组
    • union

      public static String union(String[] str, String delim)
      将一个字符串数组转换成用分隔符隔开的字符串
      参数:
      str - String[] 字符串数组
      delim - String 分隔符
      返回:
      String 用分隔符隔开的字符串
    • union

      public static String union(String[] str)
      将一个字符串数组转换成用逗号符隔开的字符串
      参数:
      str - String[] 字符串数组
      返回:
      String 用逗号符隔开的字符串
    • getToday

      public static Date getToday()
    • getToday

      public static Date getToday(int months, int days)
      取得当天的时间
      参数:
      months - 月数
      days - 天数
      返回:
      当天的时间
    • getTodayStr

      public static String getTodayStr(String pattern)
    • getTodayStr

      public static String getTodayStr(int months, int days, String pattern)
      获取当天的时间字符串
      参数:
      months - 月数
      days - 天数
      pattern - 表达式
      返回:
      String
    • getSysdate

      public static String getSysdate(DataCenter dc, String format)
      获取数据库的时间
      参数:
      dc - DataCenter
      format - String
      返回:
      String
    • getSysdate

      public static String getSysdate(DataCenter dc)
    • getSysdateDay

      public static String getSysdateDay(DataCenter dc)
    • replaceString

      public static String replaceString(String source, String tag, String value)
      将指定字符串中的标记用相应的字符串替换掉
      参数:
      source - 需要替换的字符串
      tag - 标记
      value - 替换值
      返回:
      相关标记被替换的字符串
    • encodeHTML

      public static String encodeHTML(String source)
      将文本按照HTML的要进行编码
      参数:
      source - 原始的字符串
      返回:
      转换后的字符串
    • getSystemParameter

      public static String getSystemParameter(Class cls, String paraName)
      从system.ini中读取某一参数的值
      参数:
      cls - Class
      paraName - 参数
      返回:
      参数值
    • consume

      public static String consume(Properties p, String key)
      从属性表中获取某一属性的字符串值
      参数:
      p - 属性表对象
      key - 属性名称
      返回:
      属性值
    • consumeInt

      public static int consumeInt(Properties p, String key)
      从属性表中获取某一属性代表的数值
      参数:
      p - 属性表对象
      key - 属性名称
      返回:
      属性代表的数值
    • convertNullToEmpty

      public static String convertNullToEmpty(String str)
      转换字符串,如果值为null,返回""
      参数:
      str - 字符串
      返回:
      返回经过规整的字符串
    • convertNullToDefault

      public static String convertNullToDefault(String str, String defaultValue)
      转换字符串,如果值为null,返回默认值
      参数:
      str - 字符串
      defaultValue - 默认值
      返回:
      返回经过规整的字符串
    • convertNullToHTMLEmpty

      public static String convertNullToHTMLEmpty(String str)
      将字符串中有空格的地方转化成 &nbsp
      参数:
      str - 普通字符串
      返回:
      空格经过转化后的字符串
    • PictureZoom

      public static void PictureZoom(InputStream source, Dimension target, OutputStream out)
      将图片进行自动比例缩放,从一个输入流进行缩放后输出到一个输出流中
      参数:
      source - 输入流
      target - 目标大小
      out - 输出流
    • PictureZoom

      public static void PictureZoom(InputStream source, Dimension target, OutputStream out, int keepScale)
      图片缩放函数,将一个输入流进行缩放后输出到一个输出流中
      参数:
      source - 输入流
      target - 目标大小
      out - 输出流
      keepScale - 是否保持比例 0不保持比例(拉伸),1自动保持比例,2以宽度为基准保持比例,3以高度为基准保持比例
    • outputData

      public static void outputData(InputStream input, OutputStream output, int blockSize) throws Exception
      从输入流将数据拷贝到输出流
      参数:
      input - 输入流
      output - 输出流
      blockSize - int
      抛出:
      Exception - Exception
    • outputData

      public static void outputData(InputStream input, OutputStream output) throws Exception
      默认一个字节一个字节进行传输
      参数:
      input - 输入流
      output - 输出流
      抛出:
      Exception - Exception
    • convertList2StrArray

      public static String[] convertList2StrArray(List list)
      将一个链表中的数据作为字符串数组输出
      参数:
      list - List 链表
      返回:
      String[] 字符串数组
    • addDays

      public static Date addDays(Date today, int days)
      在某一个时间的基础上增加或减少几天
      参数:
      today - Date 当前时间
      days - int 增加或者减少几天,正数表示today之后的某一天,负数表示today之前的某一天
      返回:
      Date 修改后的时间
    • addDays

      public static String addDays(String today, int days, String pattern) throws Exception
      将用字符串表示的某一格式日期增加或者减少几天
      参数:
      today - String 当天
      days - int 增减天数
      pattern - String 日期模式
      返回:
      String 经过增加或者减少的最终日期
      抛出:
      Exception - 如果出错抛出异常
    • addMonths

      public static Date addMonths(Date today, int months)
      在某一个时间的基础上增加或减少几个月
      参数:
      today - Date 当前时间
      months - int 增加或者减少几个月,正数表示today之后的某一月,负数表示today之前的某一月
      返回:
      Date 修改后的时间
    • addMonths

      public static String addMonths(String curMonth, int months, String pattern) throws Exception
      将用字符串表示的某一格式月份增加或者减少几个月
      参数:
      curMonth - String 当前月份
      months - int 增减月份数
      pattern - String 月份模式
      返回:
      String 经过增加或者减少的最终月份
      抛出:
      Exception - 如果出错抛出异常
    • getDateField

      public static int getDateField(int field, Date today)
      取得日期中的某一部分
      参数:
      field - int 表示日期中的某一部分,参见GregorianCalendar的get方法
      today - Date 日期
      返回:
      int 取得的某一部分
    • convertAcrossTable2Vertic

      public static Datastore convertAcrossTable2Vertic(Datastore acrossDS, int colType, String[] acrossDSColNames, String[] idValues, String vLabelColName, String vValueColName) throws Exception
      将横表转化成纵表,返回列名为vLabelColName、vValueColName变量指定的的数据集
      参数:
      acrossDS - Datastore 横表数据集
      colType - int 待转换的数据集中数值字段的类型,注意,所有字段的类型应该移植
      acrossDSColNames - String[] 供生成的横列名
      idValues - String[] 区分不同原横列的字段值(原横列对应的名称或意义)
      vLabelColName - String 生成的新的数据源中对应每个列说明的字段(分类字段)
      vValueColName - String 值字段
      返回:
      Datastore 新的数据集
      抛出:
      Exception - Exception
    • createRandomID

      public static String createRandomID(jakarta.servlet.http.HttpSession session)
      根据web服务器的会话(session)生成一个唯一的ID
      参数:
      session - HttpSession 用户会话
      返回:
      String 唯一的ID
    • byte2hex

      public static String byte2hex(byte[] b)
      将字节数据转换成对应的二进制字符串
      参数:
      b - byte[] 字节数组
      返回:
      String 转化后的字符串
    • getEncryptString

      public static String getEncryptString(String original)
      利用消息摘要对字符串加密,加密是单向的
      参数:
      original - String 需要加密的字符串
      返回:
      String 加密后的字符串
    • md5

      public static String md5(String original)
      MD5加密
      参数:
      original - String
      返回:
      String
    • getLinuxMachineCode

      public static String getLinuxMachineCode()
      获取Linux下的机器码
      返回:
      String
    • getWindowsMachineCode

      public static String getWindowsMachineCode()
      获取windows下的机器码
      返回:
      String
    • validUserNum

      protected static boolean validUserNum(DataCenter dc, String userId)
      验证当前登陆用户数是否到达授权用户数
      参数:
      dc -
      返回:
    • getFileDigest

      public static String getFileDigest(Class cls, String fileName)
      读取一个文件的内容,并根据文件的内容生成消息摘要
      参数:
      cls - Class
      fileName - String 文件名字
      返回:
      String 消息摘要
    • getOSName

      public static String getOSName()
      获取当前操作系统名称. return 操作系统名称 例如:windows xp,linux 等.
      返回:
      String
    • isWindows

      public static boolean isWindows()
      判断是否WINDOWS系统
      返回:
      boolean
    • isLinux

      public static boolean isLinux()
      判断是否Linux系统
      返回:
      boolean
    • getMacAddress

      public static String getMacAddress()
      获取服务器的MAC地址
      返回:
      String
    • getMacAddressEx

      protected static String getMacAddressEx()
      根据System.properties中的参数配置来获取服务器MAC地址
      返回:
      String
    • encryptMac

      protected static String encryptMac(String mac)
      通过MAC地址生成安装注册码,以防止未经授权而直接从其他地方拷贝使用该系统
      参数:
      mac - String
      返回:
      String