public class Utility extends Object
| 构造器和说明 |
|---|
Utility() |
| 限定符和类型 | 方法和说明 |
|---|---|
static boolean |
checkEmail(String email)
Check email.
|
static String |
ChineseStringToUTF(String s)
GBK ��UTF-8ת����.
|
static String |
chopAtWord(String string,
int length)
Intelligently chops a String at a word boundary (whitespace) that occurs
at the specified index in the argument or before.
|
static String |
dateToMillis(Date date)
Formats a Date as a fifteen character long String made up of the Date's
padded millisecond value.
|
static byte[] |
decodeHex(String hex)
Turns a hex encoded string into a byte array.
|
static String |
encodeHex(byte[] bytes)
Turns an array of bytes into a String representing each byte as an
unsigned hex number.
|
static String |
encrypt(String originalStr)
����һ���ַ�ļ�����ʽ��?
|
static String |
escapeForXML(String string)
Escapes all necessary characters in the String so that it can be used in
an XML doc.
|
static String |
escapeHTMLTags(String in)
Escape HTML tags.
|
static String |
getDateString(long l)
Gets the date string.
|
static Date |
getNowDate()
Gets the now date.
|
static long |
getNowLong()
Gets the now long.
|
static Date |
getNowSQLDate()
Gets the now SQL date.
|
static Time |
getNowSQLTime()
Gets the now SQL time.
|
static Timestamp |
getNowSQLTimestamp()
Gets the now SQL timestamp.
|
static String |
getString(Object o)
Gets the string.
|
static String |
getUserLink(BigDecimal id,
String name)
Gets the user link.
|
static String |
hash(String data)
Hashes a String using the Md5 algorithm and returns the result as a
String of hexadecimal numbers.
|
static boolean |
isDigital(String s)
Checks if is digital.
|
static String |
longRstr(long lon,
String str)
�������ڸ�ʽ����ʱ��.
|
static String |
randomDigital(int length)
Random digital.
|
static String |
randomString(int length)
Returns a random String of numbers and letters (lower and upper case) of
the specified length.
|
static byte[] |
ReadFromFile(String fileName)
Read from file.
|
static String |
replace(String line,
String oldString,
String newString)
Replaces all instances of oldString with newString in line.
|
static String |
replace(String line,
String oldString,
String newString,
int[] count)
Replaces all instances of oldString with newString in line.
|
static String |
replaceAMP(String p)
Replace AMP.
|
static String |
replaceCRLF(String p)
Replace CRLF.
|
static String |
replaceCRLF2(String p)
Replace CRLF 2.
|
static String |
replaceIgnoreCase(String line,
String oldString,
String newString)
Replaces all instances of oldString with newString in line with the added
feature that matches of newString in oldString ignore case.
|
static String |
replaceIgnoreCase(String line,
String oldString,
String newString,
int[] count)
Replaces all instances of oldString with newString in line with the added
feature that matches of newString in oldString ignore case.
|
static Timestamp |
string2Time(String dateString)
String 2 time.
|
static String |
toUtf8String(String s)
To utf 8 string.
|
static String |
TranslateTags(String tags)
Translate tags.
|
static String |
unescapeFromXML(String string)
Unescapes the String by converting XML escape sequences back into normal
characters.
|
static void |
WriteToFile(String filename,
byte[] content)
Write to file.
|
static String |
zeroPadString(String string,
int length)
Pads the supplied String with 0's to the specified length and returns the
result as a new String.
|
public static final Timestamp string2Time(String dateString) throws ParseException
dateString - the date stringParseException - the parse exceptionpublic static boolean checkEmail(String email)
email - the emailpublic static final String replace(String line, String oldString, String newString)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldStringpublic static final String replaceIgnoreCase(String line, String oldString, String newString)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldStringpublic static final String replaceIgnoreCase(String line, String oldString, String newString, int[] count)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldStringcount - a value that will be updated with the number of replaces
performed.public static final String replace(String line, String oldString, String newString, int[] count)
line - the String to search to perform replacements onoldString - the String that should be replaced by newStringnewString - the String that will replace all instances of oldStringcount - the countpublic static final String escapeHTMLTags(String in)
in - the text to be converted.public static final String hash(String data)
A hash is a one-way function -- that is, given an input, an output is easily computed. However, given the output, the input is almost impossible to compute. This is useful for passwords since we can store the hash and a hacker will then have a very hard time determining the original password.
In Jive, every time a user logs in, we simply take their plain text password, compute the hash, and compare the generated hash to the stored hash. Since it is almost impossible that two passwords will generate the same hash, we know if the user gave us the correct password or not. The only negative to this system is that password recovery is basically impossible. Therefore, a reset password method is used instead.
data - the String to compute the hash of.public static final String encodeHex(byte[] bytes)
Method by Santeri Paavolainen, Helsinki Finland 1996
(c) Santeri Paavolainen, Helsinki Finland 1996
Distributed under LGPL.
bytes - an array of bytes to convert to a hex-stringpublic static final byte[] decodeHex(String hex)
hex - a hex encoded String to transform into a byte array.public static final String randomString(int length)
The specified length must be at least one. If not, the method will return null.
length - the desired length of the random String to return.public static final String randomDigital(int length)
length - the lengthpublic static String replaceCRLF2(String p)
p - the ppublic static final String chopAtWord(String string, int length)
length, the String will be chopped
there. If no newline or whitespace is found in string up to
the index length, the String will chopped at
length.
For example, chopAtWord("This is a nice String", 10) will return "This is a" which is the first word boundary less than or equal to 10 characters into the original String.
string - the String to chop.length - the index in string to start looking for a
whitespace boundary at.string whose length is less than or
equal to length, and that is chopped at whitespace.public static final String escapeForXML(String string)
string - the string to escape.public static final String unescapeFromXML(String string)
string - the string to unescape.public static final String zeroPadString(String string, int length)
string - the original String to pad.length - the desired length of the new padded String.public static final String dateToMillis(Date date)
date - the datepublic static String encrypt(String originalStr)
originalStr - the original strpublic static String ChineseStringToUTF(String s)
s - the spublic static long getNowLong()
public static Date getNowDate()
public static Date getNowSQLDate()
public static Time getNowSQLTime()
public static Timestamp getNowSQLTimestamp()
public static String TranslateTags(String tags)
tags - the tagspublic static String getUserLink(BigDecimal id, String name)
id - the idname - the namepublic static boolean isDigital(String s)
s - the spublic static String getDateString(long l)
l - the lpublic static void WriteToFile(String filename, byte[] content)
filename - the filenamecontent - the contentpublic static byte[] ReadFromFile(String fileName)
fileName - the file namepublic static String toUtf8String(String s)
s - the sCopyright © 2017. All rights reserved.