/*
* TextProcessor.java
*
*/
package com.aotain.wechat.utils;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils;
import sun.misc.BASE64Decoder;
/**
* A TextProcessor is a convenient class for handling some common text
* processing.
*/
public class StringUtil {
public final static String EMPTY_STR = "";
public static String EN = "en";
public static String CH = "ch";
public static String SQL_ESCAPE_CHAR = "/";
/** Creates new TextProcessor */
private StringUtil() {
}
public static byte[] hexToBytes(String hexStr) throws Exception {
if (hexStr == null) {
return null;
}
if (hexStr.length() % 2 != 0) {
throw new Exception("Length of data is not equal to even number");
}
byte[] rtnBytes = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
rtnBytes[i] = (byte) Integer.parseInt(hexStr.substring(i * 2,
i * 2 + 2), 16);
}
return rtnBytes;
}
/**
* Convert a long value in millisec to hh:MM:ss
*/
public static String longToHHMMSS(long someTime) {
long totalSec = someTime / 1000;
long sec = totalSec % 60;
String ss = leftPad(Long.toString(sec), 2, '0');
long min = ((totalSec - sec) / 60) % 60;
String mm = leftPad(Long.toString(min), 2, '0');
String hh = Long.toString((totalSec - sec) / 3600);
return new StringBuffer().append(hh).append(':').append(mm).append(':')
.append(ss).toString();
}
public static String leftPad(String inStr, int length, char c) {
if (inStr.length() == length) {
return inStr;
}
StringBuffer outStr = new StringBuffer();
for (int i = inStr.length(); i < length; i++) {
outStr.append(c);
}
outStr.append(inStr);
return outStr.toString();
}
public static String rightPad(String inStr, int length, char c) {
if (inStr.length() == length) {
return inStr;
}
StringBuffer outStr = new StringBuffer();
outStr.append(inStr);
for (int i = inStr.length(); i < length; i++) {
outStr.append(c);
}
return outStr.toString();
}
/**
* Tokenizes a given string according to the specified delimiters. The
* characters in the delim argument are the delimiters for separating
* tokens. Delimiter characters themselves will not be treated as tokens.
*
* @param str
* A string to be parsed.
* @param delim
* The delimiters.
* @return The tokens in a String array.
*/
public static String[] tokenize(String str, String delim) {
String[] strs = null;
if (str != null) {
StringTokenizer tokens;
if (delim == null) {
tokens = new StringTokenizer(str);
} else {
tokens = new StringTokenizer(str, delim);
}
strs = new String[tokens.countTokens()];
for (int i = 0; i < strs.length && tokens.hasMoreTokens(); i++) {
strs[i] = tokens.nextToken();
}
}
return strs;
}
/**
* Tokenizes a given string according to a fixed length. If the last token's
* length is less than the fixed length specified, it will be ignored.
*
* @param str
* A string to be parsed.
* @param fixedLength
* The fixed length.
* @return The tokens in a String array.
*/
public static String[] tokenize(String str, int fixedLength) {
String[] strs = null;
if (str != null && fixedLength > 0) {
Vector<String> v = new Vector<String>();
for (int i = 0; i < str.length(); i += fixedLength) {
int next = i + fixedLength;
if (next > str.length()) {
next = str.length();
}
v.addElement(str.substring(i, next));
}
strs = v.toArray(new String[] {});
}
return strs;
}
/**
* Concatenates a String array (String tokens) into a String with the
* specified delimiter String.
*
* @param tokens
* A String array to be concatenated.
* @param delim
* The delimiter.
* @return The concatenated String.
*/
public static String concat(String[] tokens, String delim) {
return concat(tokens, EMPTY_STR, EMPTY_STR, delim);
}
/**
* Concatenates a String array (String tokens) into a String with the
* specified delimiter String, token's prefix, and token's suffix.
*
* @param tokens
* A String array to be concatenated.
* @param tokenPrefix
* The token's prefix to be concatenated.
* @param tokenSuffix
* The token's suffix to be concatenated.
* @param delim
* The delimiter.
* @return The concatenated String.
*/
public static String concat(String[] tokens, String tokenPrefix,
String tokenSuffix, String delim) {
StringBuffer s = new StringBuffer();
if (tokens != null) {
if (tokenPrefix == null) {
tokenPrefix = EMPTY_STR;
}
if (tokenSuffix == null) {
tokenSuffix = EMPTY_STR;
}
if (delim == null) {
delim = EMPTY_STR;
}
for (int i = 0; i < tokens.length; i++) {
// s += tokenPrefix+tokens[i]+tokenSuffix;
// if (i+1<tokens.length) s += delim;
s.append(tokenPrefix).append(tokens[i]).append(tokenSuffix);
if (i + 1 < tokens.length) {
s.append(delim);
}
}
}
return s.toString();
}
public static String concatIgnoreNull(String str1, String str2) {
if (null != str1 && null != str2) {
return str1.concat(str2);
}
if (null != str1) {
return str1;
}
if (null != str2) {
return str2;
}
return "";
}
/**
* Checks if a given String array contains the specified search String.
*
* @param tokens
* A String array to be searched.
* @param target
* The target search String.
* @return <PRE>
* true
* </PRE>
*
* if the given String array contains the specified search String,
*
* <PRE>
* false
* </PRE>
*
* otherwise.
*/
public static boolean contains(String[] tokens, String target) {
if (tokens != null) {
for (int i = 0; i < tokens.length; i++) {
if (tokens[i] == null) {
if (target == null) {
return true;
}
} else {
if (tokens[i].equals(target)) {
return true;
}
}
}
}
return false;
}
/**
* Repeats a given String in the specified number of times, then
* concatenates and returns it.
*
* @param s
* A String to be repeated and concatenated.
* @param occurs
* The number of times of the given String to be repeated.
* @return The concatenated String.
*/
public static String repeatString(String s, int occurs) {
StringBuffer result = new StringBuffer();
if (s != null && occurs > 0) {
for (int i = 0; i < occurs; i++) {
result.append(s);
}
}
return result.toString();
}
/**
* Checks if a given String contains only digits.
*
* @param s
* A String to be checked.
* @return <PRE>
* true
* </PRE>
*
* if the given String contains only digits,
*
* <PRE>
* false
* </PRE>
*
* otherwise.
*/
public static boolean isAllDigit(String s) {
if (s == null || s.equals(EMPTY_STR)) {
return false;
} else {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
}
public static boolean isAllAlphanumeric(String s) {
if (s == null || s.equals(EMPTY_STR)) {
return
没有合适的资源?快使用搜索试试~ 我知道了~
获取微信凭证,全局存储(java)
共43个文件
class:11个
java:11个
xml:6个
4星 · 超过85%的资源 需积分: 12 22 下载量 53 浏览量
2018-01-09
15:26:17
上传
评论
收藏 68KB RAR 举报
温馨提示
网页实现微信分享功能,这个其实在百度上是有很多例子的,而且写得也都还不错。不过我这个跟他们的不大一样。一般的博客会将分享需要的微信凭证这些写进一个项目中,本项目获取,本项目实现分享功能。而我是获取微信凭证是单独的一个项目,这样一个服务号的获取的微信凭证,可以提供给很多个项目使用,拓展性还是可以的,有需要的朋友可以参考下。 有兴趣的朋友可以参考我的博客: http://blog.csdn.net/qq_32574435/article/details/79009775
资源推荐
资源详情
资源评论
收起资源包目录
getWechatInfo.rar (43个子文件)
getWechatInfo
pom.xml 4KB
target
test-classes
m2e-wtp
web-resources
META-INF
maven
getWechatInfo
getWechatInfo
pom.xml 4KB
pom.properties 252B
MANIFEST.MF 114B
classes
conf
common.properties 213B
spring-mvc.xml 1KB
log4j.properties 2KB
com
aotain
wechat
bean
HttpResult.class 1KB
controller
ExceptionHandlerController.class 1KB
GetProofController.class 5KB
utils
Constants.class 1KB
MD5.class 4KB
DateUtils.class 16KB
WechatUtil.class 4KB
StringUtil.class 19KB
MyX509TrustManager.class 901B
Tools.class 13KB
DateFormatConstant.class 2KB
.settings
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.common.component 764B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.validation.prefs 50B
.jsdtscope 575B
org.eclipse.jdt.core.prefs 430B
src
test
java
main
webapp
WEB-INF
web.xml 2KB
resources
java
conf
common.properties 108B
spring-mvc.xml 1KB
log4j.properties 2KB
com
aotain
wechat
bean
HttpResult.java 1KB
controller
GetProofController.java 5KB
ExceptionHandlerController.java 839B
utils
Tools.java 15KB
Constants.java 768B
WechatUtil.java 2KB
StringUtil.java 34KB
DateFormatConstant.java 2KB
MD5.java 5KB
DateUtils.java 20KB
MyX509TrustManager.java 686B
.project 1KB
.classpath 1KB
共 43 条
- 1
资源评论
- qq_218471492018-09-27还行吧。。。
fly小胖
- 粉丝: 26
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功