Utils/TextUtils/src/main/java/eu/mikroskeem/utils/text/TextUtils.java

35 lines
921 B
Java

package eu.mikroskeem.utils.text;
import org.jetbrains.annotations.NotNull;
import java.util.Base64;
public class TextUtils {
/**
* Check if string contains whitespace
* @param str String to check
* @return Whether string contained whitespace or not
*/
public static boolean hasWhitespace(@NotNull String str){
return !str.matches("\\S+");
}
/**
* Encode string to Base64 (with padding)
* @param str String to encode
* @return Base64 encoded string
*/
@NotNull public static String b64enc(@NotNull String str){
return Base64.getEncoder().encodeToString(str.getBytes());
}
/**
* Decode Base64 to string
* @param b64str Base64 encoded string
* @return Decoded Base64 string
*/
@NotNull public static String b64dec(@NotNull String b64str){
return new String(Base64.getDecoder().decode(b64str));
}
}