io.mats3.util.SanitizeMqNames Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mats-util Show documentation
Show all versions of mats-util Show documentation
Mats^3 Utilities - notably the MatsFuturizer, which provides a bridge from synchronous processes to the highly asynchronous Mats^3 services.
package io.mats3.util;
import java.util.regex.Pattern;
/**
* Utility class for replacing dodgy characters from queue/topic names, and names in general, in the Message Broker
* world - it is quite restrictive, replacing any character not in [a-z,A-Z,0-9,.,_,-] (lower alpha, upper alpha,
* digits, dot, underscore, minus/dash) with '_'.
*
* The code is literally:
* Pattern.compile("[^a-zA-Z0-9._\\-]").matcher(input).replaceAll("_")
* .. but the compiled pattern is statically cached.
*
* Its functionality may very well be copied to where its logic is needed if not desired to depend on 'mats-util'.
*/
public class SanitizeMqNames {
public static final Pattern MQ_NAME_REPLACE_PATTERN = Pattern.compile("[^a-zA-Z0-9._\\-]");
/**
* Sanitizes the input, only allowing [a-z,A-Z,0-9,.,-,_] (last being dot, minus, underscore)
*
* @param input
* the name to sanitize
* @return the name after being run through the code
* 'Pattern.compile("[^a-zA-Z0-9._\\-]").matcher(input).replaceAll("_")
'.
*/
public static String sanitizeName(String input) {
return MQ_NAME_REPLACE_PATTERN.matcher(input).replaceAll("_");
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy