Class StringUtils
- java.lang.Object
-
- com.feedzai.commons.sql.abstraction.util.StringUtils
-
public class StringUtils extends Object
String Utilities.- Since:
- 2.0.0
- Author:
- Rui Vilao (rui.vilao@feedzai.com)
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringescapeSql(String str)Apache Commons-Lang 2.X contained StringEscapeUtils#escapeSql, but this method was removed in 3.X as discussed here: https://commons.apache.org/proper/commons-lang/article3_0.html#StringEscapeUtils.escapeSql For this reason, the source code has been copied from 2.X to here so that we can continue to use the logic and possibly build on it in the future.static Stringmd5(String message)Generates the MD5 checksum for the specified message.static Stringmd5(String message, int nchar)Generates de MD5 checksum for the specified message.static Stringquotize(String s)Puts quotes around a String.static Stringquotize(String s, String quoteChar)Puts quotes around a String.static StringreadString(InputStream stream)Reads a string from the input stream.static StringsingleQuotize(String s)Puts single quotes around a string.
-
-
-
Method Detail
-
quotize
public static String quotize(String s)
Puts quotes around a String.- Parameters:
s- the string to be 'quotized'- Returns:
- a the string with quotes
-
quotize
public static String quotize(String s, String quoteChar)
Puts quotes around a String.- Parameters:
s- the string to be 'quotized'- Returns:
- a the string with quotes
-
singleQuotize
public static String singleQuotize(String s)
Puts single quotes around a string.- Parameters:
s- the string to be single 'quotized'- Returns:
- a string with single quotes
-
md5
public static String md5(String message)
Generates the MD5 checksum for the specified message.- Parameters:
message- The message.- Returns:
- The hexadecimal checksum.
-
md5
public static String md5(String message, int nchar)
Generates de MD5 checksum for the specified message.- Parameters:
message- The message.nchar- The maximum number of chars for the result hash.- Returns:
- The hexadecimal checksum with the specified maximum number of chars.
-
readString
public static String readString(InputStream stream) throws IOException
Reads a string from the input stream.- Parameters:
stream- The stream.- Returns:
- The string from that stream.
- Throws:
IOException- If an I/O error occurs.
-
escapeSql
public static String escapeSql(String str)
Apache Commons-Lang 2.X contained StringEscapeUtils#escapeSql, but this method was removed in 3.X as discussed here: https://commons.apache.org/proper/commons-lang/article3_0.html#StringEscapeUtils.escapeSql For this reason, the source code has been copied from 2.X to here so that we can continue to use the logic and possibly build on it in the future. ***************** Copied from commons-lang:commons-lang:2.6 ****************Escapes the characters in a
Stringto be suitable to pass to an SQL query.For example,
statement.executeQuery("SELECT * FROM MOVIES WHERE TITLE='" + StringEscapeUtils.escapeSql("McHale's Navy") + "'");At present, this method only turns single-quotes into doubled single-quotes (
see http://www.jguru.com/faq/view.jsp?EID=8881"McHale's Navy"=>"McHale''s Navy"). It does not handle the cases of percent (%) or underscore (_) for use in LIKE clauses.- Parameters:
str- the string to escape, may be null- Returns:
- a new String, escaped for SQL,
nullif null string input
-
-