Java Code Examples for org.apache.commons.lang3.StringUtils.replaceChars()

The following are Jave code examples for showing how to use replaceChars() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: xm-commons   File: MdcUtils.java   Source Code and License Vote up 5 votes
/**
 * Generates request id based on UID and SHA-256.
 *
 * @return request identity
 */
public static String generateRid() {
    byte[] encode = Base64.getEncoder().encode(DigestUtils.sha256(UUID.randomUUID().toString()));
    try {
        String rid = new String(encode, StandardCharsets.UTF_8.name());
        rid = StringUtils.replaceChars(rid, "+/=", "");
        return StringUtils.right(rid, RID_LENGTH);
    } catch (UnsupportedEncodingException e) {
        throw new IllegalStateException(e);
    }
}
 
Example 2
Project: jigsaw-payment   File: TProtobufProcessor.java   Source Code and License Vote up 5 votes
/**
 * 将message转换成string,并用空格取代回车符和引号.
 */
private String messageToString(Message message) {
	String json = format.printToString(message);

	return StringUtils.replaceChars(StringUtils.replaceChars(
			StringUtils.left(json, MAX_REQUEST_BYTES_LENGTH), '\n', ' '),
			'"', ' ');
}
 
Example 3
Project: util   File: FilePathUtil.java   Source Code and License Vote up 5 votes
/**
 * 在Windows环境里,兼容Windows上的路径分割符,将 '/' 转回 '\'
 */
public static String normalizePath(String path) {
	if (Platforms.FILE_PATH_SEPARATOR_CHAR == Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR
			&& StringUtils.indexOf(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR) != -1) {
		return StringUtils.replaceChars(path, Platforms.LINUX_FILE_PATH_SEPARATOR_CHAR,
				Platforms.WINDOWS_FILE_PATH_SEPARATOR_CHAR);
	}
	return path;

}
 
Example 4
Project: outcomes   File: Crypto.java   Source Code and License Vote up 2 votes
/**
 * the Strings created by "newRandomId" are Base32 encoded,
 * so they can be considered case-insensitive and also insensitive
 * with regard to easily confused character like "1/I" or "0/O".
 * This function returns a normalized version of an input String
 * so that it would match an id generated by "newRandomId".
 */

public static String normalizeId(String id){
    return StringUtils.replaceChars(StringUtils.upperCase(StringUtils.stripToNull(id)), "10 -", "IO");
}