- 浏览: 110955 次
- 性别:
- 来自: 郑州
文章分类
最新评论
-
DemonLi:
我来组成点击量
linux 修改时间 ntp同步时间 -
lvinie:
Ray_Mysterio 写道请问一下,我现在安装heartb ...
heartbeat 配置 -
Ray_Mysterio:
请问一下,我现在安装heartbeat的时候出现了一个问题。两 ...
heartbeat 配置 -
Ray_Mysterio:
请问一下,我现在安装heartbeat的时候出现了一个问题。两 ...
heartbeat 配置 -
Ray_Mysterio:
请问一下,我现在安装heartbeat的时候出现了一个问题。两 ...
heartbeat 配置
import java.io.UnsupportedEncodingException; import java.security.MessageDigest; /** * 编码工具类,包括: <br> * 1)MD5/SHA编码 <br> * 2)Base64编码 <br> * 3)DES/ThreeDES编码 <br> * 4)GBK/UTF-8/ISO-8859-1/UNICODE转换 <br> */ public class CoderUtil { public static final String ALGORITHM_MD5 = "MD5"; /** * MD5 编码,返回本地编码字符串 * * @param src 源串 * @param encoding 编码 * @return 目标串 */ public static String md5Encoder(String src, String encoding) { if (src == null) return null; byte[] destBytes = md5EncoderByte(src, encoding); String dest = ""; for (int i = 0; i < 16; i++) { dest += byteToHEX(destBytes[i]); } return dest; } /** * MD5 编码,返回本地编码字符串 * * @param src 源串 默认使用UTF-8编码 * @return 目标串 */ public static String md5Encoder(String src) { return md5Encoder(src, "UTF-8"); } /** * MD5编码,返回byte数组,本地编码 * * @param src 源串 默认使用UTF-8编码 * @return 目标编码 */ public static byte[] md5EncoderByte(String src) { return md5EncoderByte(src, "UTF-8"); } /** * MD5编码,返回byte数组 * * @param src 源串 * @param encoding 编码 * @return 目标编码 */ public static byte[] md5EncoderByte(String src, String encoding) { if (src == null) return null; try { if (encoding == null) return md5EncoderByte(src.getBytes()); else return md5EncoderByte(src.getBytes(encoding)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } } /** * MD5编码,返回byte数组 * * @param buf 源byte数组 * @return 目标编码 */ public static byte[] md5EncoderByte(byte[] buf) { if (buf == null) return null; try { MessageDigest md5Temp = MessageDigest.getInstance(ALGORITHM_MD5); return md5Temp.digest(buf); } catch(Exception e) { e.printStackTrace(); return null; } } /** * Base64 编码 * * @param src 源串 * @return 目标串 */ public static String base64Encode(String src) { if (src == null) return null; return base64Encode(src.getBytes()); } /** * Base64 编码 * * @param src 源串 * @return 目标串 */ public static String base64Encode(byte[] src) { if (src == null) return null; return new String(Base64.encodeBase64(src)); } /** * Base64 编码 * * @param src 源串 * @return 目标串 */ public static String base64Encode(String src, String encoding) { if (src == null) return null; try { byte[] dest = Base64.encodeBase64(src.getBytes(encoding)); return new String(dest, encoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } /** * Base64 解码 * * @param dest 目标串 * @return 源编码 */ public static byte[] base64DecodeBytes(String dest) { if (dest == null) return null; return Base64.decodeBase64(dest.getBytes()); } /** * Base64 解码 * * @param dest 目标串 * @return 源串 */ public static String base64Decode(String dest) { if (dest == null) return null; byte[] b = Base64.decodeBase64(dest.getBytes()); return new String(b); } /** * Base64 解码 * * @param dest 目标串 * @return 源串 */ public static String base64Decode(String dest, String encoding) { if (dest == null) return null; try { byte[] b = Base64.decodeBase64(dest.getBytes(encoding)); return new String(b, encoding); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } /** * Base64 解码 * * @param dest 目标串 * @return 源编码 */ public static byte[] base64DecodeBytes(String dest, String encoding) { if (dest == null) return null; try { return Base64.decodeBase64(dest.getBytes(encoding)); } catch (UnsupportedEncodingException e) { throw new IllegalArgumentException(e); } } /** * 把字节转换为16进制字符 * * @param ib * @return */ public static String byteToHEX(byte ib) { char[] Digit = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; char [] ob = new char[2]; ob[0] = Digit[(ib >>> 4) & 0X0F]; ob[1] = Digit[ib & 0x0F]; String s = new String(ob); return s; } /** * 给定一个url,和key,取得value * 此方法仅供参考,不作解释 * @param url * @param key * @return String 给定一个url,和key,取得value */ public static String getURLValue(String url,String key) { if(isEmpty(url) || isEmpty(key)) return ""; int p = url.indexOf("?"); if (p != -1) url = url.substring(p); if (!url.startsWith("?")) url = "?" + url; int index = url.indexOf(key); if(index == -1) return ""; if ((url.charAt(index-1) != '?' && url.charAt(index-1) != '&') || index+key.length()>=url.length() || url.charAt(index+key.length()) != '=') return ""; int point = index + key.length(); int valueIndex = url.indexOf('&',point); if (valueIndex == -1) return url.substring(point+1,url.length()); return url.substring(point+1,valueIndex); } /** 检查字符串是否为空 */ private static boolean isEmpty(String s) { return ((s == null) || (s.trim().length() == 0)); } /** * 读取XML中字段的值,允许没有field时返回空字符串 * 此方法仅供参考,不作解释 * @param xml XML字符串 * @param field 字段名 * @return 返回XML中字段中的值 * @throws Exception 如果字段内容不符合要求,则抛出此异常 */ public static String getXmlField(String xml, String field) throws Exception { if (xml.length() < field.length() * 2 + 5) { throw new Exception("xml tag #"+field+"# format error"); } String lField = "<"+field+">"; String rField = "</"+field+">"; int iLeft = xml.indexOf(lField); int iRight = xml.indexOf(rField); if (iLeft == -1 && iRight == -1) return ""; if ((iLeft == -1 && iRight != -1) || (iLeft != -1 && iRight == -1)) { throw new Exception("xml tag #"+field+"# format error"); } int valueLen = iRight - iLeft - lField.length(); if (valueLen <= 0) return ""; return xml.substring(iLeft + lField.length(), iRight); } /** * 读取XML中字段的int值 * 此方法仅供参考,不作解释 * @param xml XML字符串 * @param field 字段名 * @return int 返回XML中字段中的int值 * @throws Exception 如果字段不是int或格式不正确,则抛出此异常 */ public static int getXmlFieldInt(String xml, String field) throws Exception { if (xml.length() < field.length() * 2 + 5) { throw new Exception("xml tag #"+field+"# format error"); } String lField = "<"+field+">"; String rField = "</"+field+">"; int iLeft = xml.indexOf(lField); int iRight = xml.indexOf(rField); if (iLeft == -1 || iRight == -1) { throw new Exception("xml tag #"+field+"# format error"); } int valueLen = iRight - iLeft; if (valueLen < 1)//nubmer不允许为空 { throw new Exception("xml tag #"+field+"# format error"); } String valueInt = xml.substring(iLeft + lField.length(), iRight); if (!isInteger(valueInt)) { throw new Exception("xml tag #"+field+"# format error"); } return Integer.parseInt(valueInt); } /** 检查是否是整型 */ private static boolean isInteger(String s) { if (isEmpty(s)) return false; // 逐个检查,如果出现一个字符不是数字则返回false for (int i = 0; i < s.length(); i++) { if ("0123456789".indexOf(s.charAt(i)) == -1) return false; } return true; } }
发表评论
-
java发送http的get、post请求
2014-05-22 13:41 639package wzh.Http; impor ... -
Java中的instanceof关键字
2012-05-22 09:40 0instanceof是Java的一个二元操作 ... -
tomcat 最大连接数配置
2011-10-10 13:01 1249server.xml中配置 <Connector ... -
tomcat start stop 脚本
2011-10-05 17:49 2195创建文件tomcat,文件内容如下 [root@ ... -
读取config 工具类
2011-09-05 14:35 1244import java.io.File; import ja ... -
java的System.getProperty()方法可以获取的值
2011-09-05 14:18 607java.version Java ... -
MySql 备份还原常用命令
2011-09-02 11:22 808备份MySQL数据库的命令 mys ... -
struts2的struts.properties配置文件详解
2011-08-13 14:04 835struts.action.extension ... -
java(Web)中相对路径,绝对路径问题总结
2011-08-02 09:39 702前一段时间,由于在处理Web应用下的文件创建与移动 ... -
java中的io系统详解 (转)
2011-08-01 20:24 639Java 流在处理上分为字符流和字节流。字符流处理的 ... -
Struts2配置文件详解——struts-default.xml
2011-07-31 11:55 742<?xml version="1.0" ... -
Struts 2的基石——拦截器(Interceptor)
2011-07-31 10:41 798Interceptor(以下译为拦 ... -
JAVA中的时间操作 转
2011-07-26 17:16 757java 中的时间操作不外 ... -
org.springframework.web.util.IntrospectorCleanupListener是什么东东
2011-07-21 19:13 5996看到好多项目的web.xml中都配置了 <listen ... -
PO VO FormBean
2011-04-20 16:13 953概念: PO是持 ... -
ActionForm工作流程
2011-04-20 16:13 1185工作原理: 处理ActionForm的一般步骤: ... -
actionForm声明周期
2011-04-20 16:12 772看了很多的资料书籍,都提了一下ActionForm ... -
EL表达式 js基础
2011-04-20 16:12 1490El表达式 1.EL表达式需要的环境:servlet2.4 ... -
郁闷的 NoSuchMethodError
2011-04-20 16:11 1196最近做程序时 就是自 ... -
servlet 中使用Spring自动注入的bean
2011-04-13 10:49 1717用servlet的时候遇到一个问题,想往servlet中直接注 ...
相关推荐
C# Util 实用工具类 ,包含:Json、Net、Time、Compress、Config、Enums、File等等等常用使用工具类
提供Swift丰富的扩展和实用工具类,并大多数支持Objective-C。.zip提供Swift丰富的扩展和实用工具类,并大多数支持Objective-C。.zip提供Swift丰富的扩展和实用工具类,并大多数支持Objective-C。.zip提供Swift丰富...
fastjson实用工具类
post方法等实用工具类 强大的工具类 新手方便快速编程
JAVA实用工具类
java实用工具类介绍
实用工具类开发和维护会耗费程序员的时间。GS通过提供几个高质量的库,从而简化了此过程,您可以将这些库轻松集成到现有的代码库中。
Hutool是一个功能丰富且易用的Java工具库,通过诸多实用工具类的使用,旨在帮助开发者快速、便捷地完成各类开发任务。 这些封装的工具涵盖了字符串、数字、集合、编码、日期、文件、IO、加密、数据库JDBC、JSON、...
Timestampy用于处理UNIX时间戳一堆实用工具类
Java实用工具类(后端开发必备), GZIPUtil、HttpUtil、HttpUtil、NetworkUtil、RegexUtils、PropertiesUtil、DateUtil、BigDecimalUtil、EmailUtil、FastJsonUtil、ProtobufUtil等等
常用Java知识的汇总、实用工具类的集合.zip适合学习/练手、毕业设计、课程设计、期末/期中/大作业、工程实训、相关项目/竞赛学习等。 项目具有较高的学习借鉴价值,也可直接拿来修改复现。可以在这些基础上学习借鉴...
Excel表格操作实用工具类,使用泛型,反射,POI等技术编写的一个Excel表格操作工具类,适用于各种实体封装的报表表格导入导出,下载模板等功能
Cake Utility -CakePHP实用工具类。如Inflector、字符串、散列、安全性和Xml。
Java访问MongoDB的实用工具类,包括增、删、改、查、distinct、group、mapreduce等,具备常用的MongoDB操作,可以简化基于MongoDB的Java程序开发。
常用、实用工具
YYAsyncLayer, 用于异步呈现和显示的iOS实用工具类 YYAsyncLayer 用于异步呈现和显示的iOS实用工具类。( 它被 YYText 使用)简单用法@interface YYLabel : UIView@property NSString *
用于简化数据,函数,promises等工作的JavaScript实用工具类
提供Swift丰富的扩展和实用工具类,并大多数支持Objective-C.zip
electron-util 开发Electron应用和模块的实用工具类
pareto.js - 非常小,直观和快速实用工具类集合的JavaScript库