/** * Validation method to guarantee that an err value passed in is valid by * smpp 3.4 spec * * @param errorCode * @return */ private static boolean isValidErrorCode(String errorCode) { if (StringUtil.isEmpty(errorCode) || (!StringUtil.isEmpty(errorCode) && errorCode.length() <= FIELD_ERR_MAX_LEN)) return true; else return false; }
@Override public void appendBodyToString(StringBuilder buffer) { buffer.append("(serviceType ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.serviceType)); buffer.append("] messageId ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.messageId)); buffer.append("] sourceAddr ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.sourceAddress)); buffer.append("] destAddr ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.destAddress)); buffer.append("])"); }
/** * Normalize a SQL identifer, up-casing if <regular identifer>, * and handling of <delimited identifer> (SQL 2003, section 5.2). * The normal form is used internally in Derby. * * @param id syntacically correct SQL identifier */ public static String normalizeSQLIdentifier(String id) { if (id.length() == 0) { return id; } if (id.charAt(0) == '"' && id.length() >= 3 && id.charAt(id.length() - 1) == '"') { // assume syntax is OK, thats is, any quotes inside are doubled: return StringUtil.compressQuotes( id.substring(1, id.length() - 1), "\"\""); } else { return StringUtil.SQLToUpperCase(id); } }
/** * Searches the string for occurrences of the pattern $ENV{key} and * attempts to replace this pattern with a value from the System environment * obtained using the 'key'. For example, including "$ENV{USERNAME}" in * a string and calling this method would then attempt to replace the entire * pattern with the value of the environment variable "USERNAME". The System * environment is obtained in Java with a call to System.getenv(). An environment variable is typically * defined in the Linux shell or Windows property tabs. NOTE: A Java System * property is not the same as an environment variable. * @param string0 The string to perform substitution on such as "Hello $ENV{USERNAME}". * This string may be null, empty, or contain one or more substitutions. * @return A string with all occurrences of keys substituted with their * values obtained from the System environment. Can be null if the * original string was null. * @throws SubstitutionException Thrown if a starting string was found, but the * ending string was not. Also, thrown if a key value was empty such * as using "$ENV{}". Finally, thrown if the property key was not * found in the properties object (could not be replaced). * @see #substituteWithProperties(java.lang.String, java.lang.String, java.lang.String, java.util.Properties) */ public static String substituteWithEnvironment(String string0) throws SubstitutionException { // turn environment into properties Properties envProps = new Properties(); // add all system environment vars to the properties envProps.putAll(System.getenv()); // delegate to other method using the default syntax $ENV{<key>} return substituteWithProperties(string0, "$ENV{", "}", envProps); }
private static Key getKey(String key) { try { byte[] bytes = StringUtil.getAsciiBytes(key); DESKeySpec pass = new DESKeySpec(bytes); SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); SecretKey s = skf.generateSecret(pass); return s; } catch (Exception e) { e.printStackTrace(); } return null; } }
public static String generateKey() { try { KeyGenerator keygen = KeyGenerator.getInstance("DES"); SecretKey desKey = keygen.generateKey(); byte[] bytes = desKey.getEncoded(); return StringUtil.getAsciiString(bytes); } catch (Exception e) { e.printStackTrace(); return null; } }
/** Compares two strings * Strings will be uppercased in english and compared * equivalent to s1.equalsIgnoreCase(s2) * throws NPE if s1 is null * * @param s1 first string to compare * @param s2 second string to compare * * @return true if the two upppercased ENGLISH values are equal * return false if s2 is null */ public static boolean SQLEqualsIgnoreCase(String s1, String s2) { if (s2 == null) { return false; } else { return SQLToUpperCase(s1).equals(SQLToUpperCase(s2)); } }
if (!StringUtil.containsOnlyDigits(address)) { throw new IllegalArgumentException("Address must only contain digits");
String capitalizedName = StringUtil.capitalize(propertyName); String getMethodName = "get" + capitalizedName; String setMethodName = "set" + capitalizedName;
/** * Creates an InputStream containing the document resulting from replacing template * parameters in the given InputStream source. * @param source The source stream * @param props The properties * @param startStr The String that marks the start of a replacement key such as "${" * @param endStr The String that marks the end of a replacement key such as "}" * @return An InputStream containing the resulting document. */ static public InputStream replaceProperties(InputStream source, Properties props, String startStr, String endStr) throws IOException, SubstitutionException { String template = streamToString(source); String replaced = StringUtil.substituteWithProperties(template, startStr, endStr, props); System.err.println(template); System.err.println(replaced); return new ByteArrayInputStream(replaced.getBytes()); }
private static Key getKey(String key) { try { byte[] bytes = StringUtil.getAsciiBytes(key); DESKeySpec pass = new DESKeySpec(bytes); SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); SecretKey s = skf.generateSecret(pass); return s; } catch (Exception e) { e.printStackTrace(); } return null; } }
public static String generateKey() { try { KeyGenerator keygen = KeyGenerator.getInstance("DES"); SecretKey desKey = keygen.generateKey(); byte[] bytes = desKey.getEncoded(); return StringUtil.getAsciiString(bytes); } catch (Exception e) { e.printStackTrace(); return null; } }
/** Compares two strings * Strings will be uppercased in english and compared * equivalent to s1.equalsIgnoreCase(s2) * throws NPE if s1 is null * * @param s1 first string to compare * @param s2 second string to compare * * @return true if the two upppercased ENGLISH values are equal * return false if s2 is null */ public static boolean SQLEqualsIgnoreCase(String s1, String s2) { if (s2 == null) { return false; } else { return SQLToUpperCase(s1).equals(SQLToUpperCase(s2)); } }
if (!StringUtil.containsOnlyDigits(address)) { throw new IllegalArgumentException("Address must only contain digits");
String capitalizedName = StringUtil.capitalize(propertyName); String getMethodName = "get" + capitalizedName; String setMethodName = "set" + capitalizedName;
/** * Validation method to guarantee that an err value passed in is valid by * smpp 3.4 spec * * @param errorCode * @return */ private static boolean isValidErrorCode(String errorCode) { if (StringUtil.isEmpty(errorCode) || (!StringUtil.isEmpty(errorCode) && errorCode.length() <= FIELD_ERR_MAX_LEN)) return true; else return false; }
@Override protected void appendBodyToString( StringBuilder buffer ){ buffer.append("( sourceAddr ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.sourceAddress)); buffer.append("] esmeAddr ["); buffer.append(StringUtil.toStringWithNullAsEmpty(this.esmeAddress)); buffer.append("])"); }
/** * Normalize a SQL identifer, up-casing if <regular identifer>, * and handling of <delimited identifer> (SQL 2003, section 5.2). * The normal form is used internally in Derby. * * @param id syntacically correct SQL identifier */ public static String normalizeSQLIdentifier(String id) { if (id.length() == 0) { return id; } if (id.charAt(0) == '"' && id.length() >= 3 && id.charAt(id.length() - 1) == '"') { // assume syntax is OK, thats is, any quotes inside are doubled: return StringUtil.compressQuotes( id.substring(1, id.length() - 1), "\"\""); } else { return StringUtil.SQLToUpperCase(id); } }
/** * Searches the string for occurrences of the pattern $ENV{key} and * attempts to replace this pattern with a value from the System environment * obtained using the 'key'. For example, including "$ENV{USERNAME}" in * a string and calling this method would then attempt to replace the entire * pattern with the value of the environment variable "USERNAME". The System * environment is obtained in Java with a call to System.getenv(). An environment variable is typically * defined in the Linux shell or Windows property tabs. NOTE: A Java System * property is not the same as an environment variable. * @param string0 The string to perform substitution on such as "Hello $ENV{USERNAME}". * This string may be null, empty, or contain one or more substitutions. * @return A string with all occurrences of keys substituted with their * values obtained from the System environment. Can be null if the * original string was null. * @throws SubstitutionException Thrown if a starting string was found, but the * ending string was not. Also, thrown if a key value was empty such * as using "$ENV{}". Finally, thrown if the property key was not * found in the properties object (could not be replaced). * @see #substituteWithProperties(java.lang.String, java.lang.String, java.lang.String, java.util.Properties) */ public static String substituteWithEnvironment(String string0) throws SubstitutionException { // turn environment into properties Properties envProps = new Properties(); // add all system environment vars to the properties envProps.putAll(System.getenv()); // delegate to other method using the default syntax $ENV{<key>} return substituteWithProperties(string0, "$ENV{", "}", envProps); }
/** * Hashes the input String into a Base-64 encoded hashed String. * <ul> * <li>MD5 - hash is always 24 char base-64 * <li>SHA1 - hash is always 28 char base-64 * <li>SHA256 - hash is always 44 char base-64 * <li>SHA512 - hash is always 88 char base-64 * </ul> * @param string0 The String to hash. This assumes its an ASCII string. * @return The Base-64 encoded hashed String * @throws NoSuchAlgorithmException */ public String toHashedBase64String(String string0) throws NoSuchAlgorithmException { return this.toHashedBase64String(StringUtil.getAsciiBytes(string0)); }