Package de.fraunhofer.iosb.ilt.sta
Class Utils
- java.lang.Object
-
- de.fraunhofer.iosb.ilt.sta.Utils
-
public class Utils extends Object
- Author:
- scf
-
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
cleanForLogging(String string)
Removes characters that might break logging output.static String
cleanForLogging(String string, int maxLength)
Removes characters that might break logging output and truncates to a maximum length.Currently: \n, \r and \tstatic org.apache.http.impl.client.CloseableHttpClient
createInsecureHttpClient()
static String
escapeForStringConstant(String in)
Replaces all ' in the string with ''.static boolean
isNullOrEmpty(String string)
Returns true if the given string is null, or empty.static String
quoteForUrl(Object in)
static void
throwIfNotOk(org.apache.http.client.methods.HttpRequestBase request, org.apache.http.client.methods.CloseableHttpResponse response)
Throws a StatusCodeException if the given response did not have status code 2xxstatic String
urlEncode(String string)
Urlencodes the given stringstatic String
urlEncode(String string, boolean notSlashes)
Urlencodes the given string, optionally not encoding forward slashes.static String
urlEncodeNotSlashes(String string)
Urlencodes the given string, except for the forward slashes.
-
-
-
Method Detail
-
cleanForLogging
public static String cleanForLogging(String string)
Removes characters that might break logging output. Currently: \n, \r and \t- Parameters:
string
- The string to clean.- Returns:
- The cleaned string.
-
cleanForLogging
public static String cleanForLogging(String string, int maxLength)
Removes characters that might break logging output and truncates to a maximum length.Currently: \n, \r and \t- Parameters:
string
- The string to clean.maxLength
- The maximum length of the returned String.- Returns:
- The cleaned string.
-
isNullOrEmpty
public static boolean isNullOrEmpty(String string)
Returns true if the given string is null, or empty.- Parameters:
string
- the string to check.- Returns:
- true if string == null || string.isEmpty()
-
escapeForStringConstant
public static String escapeForStringConstant(String in)
Replaces all ' in the string with ''.- Parameters:
in
- The string to escape.- Returns:
- The escaped string.
-
urlEncode
public static String urlEncode(String string, boolean notSlashes)
Urlencodes the given string, optionally not encoding forward slashes. In urls, forward slashes before the "?" must never be urlEncoded. Urlencoding of slashes could otherwise be used to obfuscate phising URLs.- Parameters:
string
- The string to urlEncode.notSlashes
- If true, forward slashes are not encoded.- Returns:
- The urlEncoded string.
-
urlEncode
public static String urlEncode(String string)
Urlencodes the given string- Parameters:
string
- The string to urlEncode.- Returns:
- The urlEncoded string.
-
urlEncodeNotSlashes
public static String urlEncodeNotSlashes(String string)
Urlencodes the given string, except for the forward slashes.- Parameters:
string
- The string to urlEncode.- Returns:
- The urlEncoded string.
-
throwIfNotOk
public static void throwIfNotOk(org.apache.http.client.methods.HttpRequestBase request, org.apache.http.client.methods.CloseableHttpResponse response) throws StatusCodeException
Throws a StatusCodeException if the given response did not have status code 2xx- Parameters:
request
- The request that generated the response.response
- The response to check the status code of.- Throws:
StatusCodeException
- If the response was not 2xx.
-
createInsecureHttpClient
public static org.apache.http.impl.client.CloseableHttpClient createInsecureHttpClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException
-
-