public class Utils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static long |
DAY |
static java.util.regex.Pattern |
emailRegex |
static long |
HOUR |
static java.util.regex.Pattern |
httpRegex |
static java.lang.String |
KEY |
static int |
MAX_FILE_SIZE |
static long |
MINUTE |
static java.lang.String[] |
MONTHS |
static java.util.Map<java.lang.String,java.lang.String> |
profanityMap |
static java.lang.ThreadLocal<java.util.Random> |
random |
static org.owasp.html.PolicyFactory |
sanitizer |
static int |
URL_TIMEOUT |
static java.util.regex.Pattern |
wwwRegex |
static javax.xml.parsers.DocumentBuilderFactory |
xmlFactory |
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
buildZeroPrefixAndTruncTrailZeros(int number,
int totalDigits) |
static java.lang.String |
bytesToHex(byte[] bytes) |
static java.lang.String |
camelCaseToLowerCase(java.lang.String text)
Convert camel case to lower case words.
|
static java.lang.String |
capitalize(java.lang.String text)
Capitalize the first character of the string.
|
static void |
checkHTML(java.lang.String text)
Check if the text contains a HTML.
|
static boolean |
checkLowMemory() |
static boolean |
checkLowMemory(double ratio) |
static boolean |
checkMaxMemory() |
static boolean |
checkProfanity(java.lang.String text)
If the word is profanity, map it to something less offensive.
|
static void |
checkScript(java.lang.String text)
Check if the text contains a script.
|
static java.lang.String |
checkURL(java.lang.String url)
Ensure the string is a valid url.
|
static java.lang.String |
compress(java.lang.String text,
int size)
Compress the text to be a proper identifier within the size limit.
|
static boolean |
containsHTML(java.lang.String text)
Check if the text contains HTML tags.
|
static boolean |
containsScript(java.lang.String text)
Check if the text contains a script.
|
static byte[] |
createThumb(byte[] image,
int size) |
static byte[] |
createThumb(byte[] image,
int size,
boolean stretch) |
static java.util.List<java.lang.String> |
csv(java.lang.String csv) |
static byte[] |
decodeBase64(java.lang.String s) |
static java.lang.String |
decodeURL(java.lang.String url) |
static java.lang.String |
decrypt(java.lang.String key,
java.lang.String ciphertext) |
static java.lang.String |
displayDate(java.util.Date date) |
static java.lang.String |
displayTime(java.util.Date date) |
static java.lang.String |
displayTimestamp(java.util.Date date) |
static java.lang.String |
encodeBase64(byte[] buf) |
static java.lang.String |
encodeURL(java.lang.String url) |
static java.lang.String |
encrypt(java.lang.String key,
java.lang.String password) |
static java.lang.String |
escapeHTML(java.lang.String html)
Escape HTML elements.
|
static java.lang.String |
escapeQuotes(java.lang.String text)
Escape quotes using \".
|
static java.lang.String |
escapeQuotesJS(java.lang.String text)
Escape quotes using \".
|
static java.lang.String |
fetchResponse(org.apache.http.HttpResponse response) |
static java.lang.String |
formatHTMLOutput(java.lang.String text)
Format the text that may be HTML, or may be text, or markup, or a mix.
|
static int[] |
getDimensions(byte[] image) |
static java.util.List<java.lang.String> |
getWords(java.lang.String text)
Tokenize the sentence into its words.
|
static byte[] |
hexToBytes(java.lang.String s) |
static java.lang.String |
httpAuthGET(java.lang.String url,
java.lang.String user,
java.lang.String password) |
static java.lang.String |
httpAuthGET(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String agent) |
static java.lang.String |
httpAuthPOST(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.util.Map<java.lang.String,java.lang.String> formParams) |
static java.lang.String |
httpAuthPOST(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String type,
java.lang.String data) |
static java.lang.String |
httpAuthPOST(java.lang.String url,
java.lang.String user,
java.lang.String password,
java.lang.String agent,
java.lang.String type,
java.lang.String data) |
static java.lang.String |
httpDELETE(java.lang.String url) |
static java.lang.String |
httpDELETE(java.lang.String url,
java.lang.String type,
java.lang.String data) |
static java.lang.String |
httpGET(java.lang.String url) |
static java.lang.String |
httpGET(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> headers) |
static java.lang.String |
httpPOST(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> formParams) |
static java.lang.String |
httpPOST(java.lang.String url,
java.util.Map<java.lang.String,java.lang.String> formParams,
java.util.Map<java.lang.String,java.lang.String> headers) |
static java.lang.String |
httpPOST(java.lang.String url,
java.lang.String type,
java.lang.String data) |
static java.lang.String |
httpPOST(java.lang.String url,
java.lang.String type,
java.lang.String data,
java.util.Map<java.lang.String,java.lang.String> headers) |
static java.lang.String |
httpPUT(java.lang.String url,
java.lang.String type,
java.lang.String data) |
static boolean |
isAlphaNumeric(java.lang.String text) |
static boolean |
isCapitalized(java.lang.String text)
Check if a capitalized word.
|
static boolean |
isCaps(java.lang.String text)
Check if the text is all upper case.
|
static boolean |
isEnglish(java.lang.String word)
Return if the string only contains English characters.
|
static boolean |
isProfanity(java.lang.String text)
Check if the text contains any profanity.
|
static java.lang.String |
linkHTML(java.lang.String text) |
static byte[] |
loadBinaryFile(java.io.InputStream stream,
boolean close,
int max)
Process the binary file and return the bytes, or an error if the file size exceed the max size.
|
static java.lang.String |
loadTextFile(java.io.InputStream stream,
java.lang.String encoding,
int maxSize)
Get the contents of the stream to a .self file and parse it.
|
static java.lang.String |
mapProfanity(java.lang.String word)
If the word is profanity, map it to something less offensive.
|
static java.io.InputStream |
openStream(java.net.URL url) |
static java.io.InputStream |
openStream(java.net.URL url,
int timeout) |
static java.sql.Date |
parseDate(java.lang.String value)
Parse the date of the form, "yyyy-MM-dd".
|
static java.util.Calendar |
parseDate(java.lang.String value,
java.lang.String format)
Parse the date of the format.
|
static java.sql.Time |
parseTime(java.lang.String value)
Parse the time of the form, "HH:mm:ss.N".
|
static java.sql.Timestamp |
parseTimestamp(java.lang.String value)
Parse the date of the form, "yyyy-MM-dd HH:mm:ss.N".
|
static org.w3c.dom.Element |
parseXML(java.lang.String xml) |
static java.lang.String |
printDate(java.util.Calendar date)
Print the date in the form, "yyyy-MM-dd HH:mm:ss.S".
|
static java.lang.String |
printDate(java.util.Date date)
Print the date in the form, "yyyy-MM-dd HH:mm:ss.N".
|
static java.lang.String |
printDate(java.util.Date date,
java.lang.String format)
Print the time in the format.
|
static java.lang.String |
printTime(java.sql.Time time,
java.lang.String format)
Print the time in the format.
|
static java.lang.String |
printTimestamp(java.sql.Timestamp timestamp)
Print the date in the form, "yyyy-MM-dd HH:mm:ss.N".
|
static java.lang.String |
printXML(org.w3c.dom.Node element) |
static java.util.Random |
random() |
static <T> T |
random(java.util.Collection<T> collection) |
static int |
random(int max) |
static <T> T |
random(java.util.List<T> list) |
static java.lang.String |
reduce(java.lang.String sentence)
Reduce the sentence to a simple form.
|
static java.lang.String |
removeCRs(java.lang.String text)
Remove cr.
|
static java.lang.String |
sanitize(java.lang.String html) |
static org.owasp.html.PolicyFactory |
sanitizer() |
static void |
sleep(int millis) |
static java.lang.String |
stripTag(java.lang.String html,
java.lang.String tag)
Strip the html tags from the text.
|
static java.lang.String |
stripTagClass(java.lang.String html,
java.lang.String tagClass)
Strip the html tags of the class from the text.
|
static java.lang.String |
stripTags(java.lang.String html)
Strip the html tags from the text.
|
static java.lang.String |
translateProfanity(java.lang.String text)
If the word is profanity, map it to something less offensive.
|
static double |
truncate(double value) |
static java.lang.String |
truncate(java.lang.String text,
int size)
Truncate the string.
|
public static int MAX_FILE_SIZE
public static long MINUTE
public static long HOUR
public static long DAY
public static int URL_TIMEOUT
public static java.lang.String KEY
public static java.util.Map<java.lang.String,java.lang.String> profanityMap
public static java.lang.ThreadLocal<java.util.Random> random
public static javax.xml.parsers.DocumentBuilderFactory xmlFactory
public static org.owasp.html.PolicyFactory sanitizer
public static java.lang.String[] MONTHS
public static java.util.regex.Pattern httpRegex
public static java.util.regex.Pattern wwwRegex
public static java.util.regex.Pattern emailRegex
public static java.util.Random random()
public static org.owasp.html.PolicyFactory sanitizer()
public static java.lang.String sanitize(java.lang.String html)
public static boolean checkMaxMemory()
public static boolean checkLowMemory()
public static boolean checkLowMemory(double ratio)
public static java.lang.String encodeURL(java.lang.String url)
public static java.lang.String decodeURL(java.lang.String url)
public static int random(int max)
public static <T> T random(java.util.List<T> list)
public static <T> T random(java.util.Collection<T> collection)
public static boolean isProfanity(java.lang.String text)
public static java.lang.String mapProfanity(java.lang.String word)
public static java.lang.String translateProfanity(java.lang.String text)
public static java.lang.String stripTags(java.lang.String html)
public static java.lang.String stripTag(java.lang.String html, java.lang.String tag)
public static java.lang.String stripTagClass(java.lang.String html, java.lang.String tagClass)
public static java.util.List<java.lang.String> csv(java.lang.String csv)
public static java.lang.String escapeHTML(java.lang.String html)
public static java.lang.String httpGET(java.lang.String url) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpGET(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> headers) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpDELETE(java.lang.String url) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpAuthGET(java.lang.String url, java.lang.String user, java.lang.String password) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpAuthGET(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String agent) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpAuthPOST(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String type, java.lang.String data) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpAuthPOST(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String agent, java.lang.String type, java.lang.String data) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpPOST(java.lang.String url, java.lang.String type, java.lang.String data) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpPOST(java.lang.String url, java.lang.String type, java.lang.String data, java.util.Map<java.lang.String,java.lang.String> headers) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpDELETE(java.lang.String url, java.lang.String type, java.lang.String data) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpPUT(java.lang.String url, java.lang.String type, java.lang.String data) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpAuthPOST(java.lang.String url, java.lang.String user, java.lang.String password, java.util.Map<java.lang.String,java.lang.String> formParams) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpPOST(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> formParams) throws java.lang.Exception
java.lang.Exception
public static java.lang.String httpPOST(java.lang.String url, java.util.Map<java.lang.String,java.lang.String> formParams, java.util.Map<java.lang.String,java.lang.String> headers) throws java.lang.Exception
java.lang.Exception
public static java.lang.String fetchResponse(org.apache.http.HttpResponse response) throws java.lang.Exception
java.lang.Exception
public static java.lang.String escapeQuotes(java.lang.String text)
public static java.lang.String escapeQuotesJS(java.lang.String text)
public static java.lang.String removeCRs(java.lang.String text)
public static boolean checkProfanity(java.lang.String text)
public static void checkScript(java.lang.String text)
public static boolean containsScript(java.lang.String text)
public static void checkHTML(java.lang.String text)
public static boolean containsHTML(java.lang.String text)
public static java.lang.String checkURL(java.lang.String url)
public static java.lang.String linkHTML(java.lang.String text)
public static java.util.List<java.lang.String> getWords(java.lang.String text)
public static org.w3c.dom.Element parseXML(java.lang.String xml)
public static java.lang.String printXML(org.w3c.dom.Node element)
public static java.sql.Date parseDate(java.lang.String value)
public static java.sql.Time parseTime(java.lang.String value)
public static java.sql.Timestamp parseTimestamp(java.lang.String value)
public static java.lang.String buildZeroPrefixAndTruncTrailZeros(int number, int totalDigits)
public static java.util.Calendar parseDate(java.lang.String value, java.lang.String format) throws java.text.ParseException
java.text.ParseException
public static java.lang.String printDate(java.util.Calendar date)
public static java.lang.String printTime(java.sql.Time time, java.lang.String format)
public static java.lang.String printDate(java.util.Date date, java.lang.String format)
public static java.lang.String printTimestamp(java.sql.Timestamp timestamp)
public static java.lang.String printDate(java.util.Date date)
public static void sleep(int millis)
public static java.lang.String compress(java.lang.String text, int size)
public static java.lang.String truncate(java.lang.String text, int size)
public static double truncate(double value)
public static java.lang.String loadTextFile(java.io.InputStream stream, java.lang.String encoding, int maxSize)
public static java.lang.String capitalize(java.lang.String text)
public static java.lang.String reduce(java.lang.String sentence)
public static boolean isEnglish(java.lang.String word)
public static boolean isCapitalized(java.lang.String text)
public static boolean isCaps(java.lang.String text)
public static java.lang.String camelCaseToLowerCase(java.lang.String text)
public static boolean isAlphaNumeric(java.lang.String text)
public static java.lang.String encrypt(java.lang.String key, java.lang.String password)
public static java.lang.String decrypt(java.lang.String key, java.lang.String ciphertext)
public static java.lang.String bytesToHex(byte[] bytes)
public static byte[] hexToBytes(java.lang.String s)
public static java.lang.String encodeBase64(byte[] buf)
public static byte[] decodeBase64(java.lang.String s)
public static java.io.InputStream openStream(java.net.URL url) throws java.io.IOException
java.io.IOException
public static java.io.InputStream openStream(java.net.URL url, int timeout) throws java.io.IOException
java.io.IOException
public static byte[] createThumb(byte[] image, int size)
public static byte[] createThumb(byte[] image, int size, boolean stretch)
public static int[] getDimensions(byte[] image)
public static java.lang.String formatHTMLOutput(java.lang.String text)
public static java.lang.String displayTime(java.util.Date date)
public static java.lang.String displayTimestamp(java.util.Date date)
public static java.lang.String displayDate(java.util.Date date)
public static byte[] loadBinaryFile(java.io.InputStream stream, boolean close, int max)