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

35 lines
921 B
Java
Raw Normal View History

2016-09-22 17:55:45 +03:00
package eu.mikroskeem.utils.text;
import org.jetbrains.annotations.NotNull;
2016-09-22 18:01:10 +03:00
import java.util.Base64;
2016-09-22 17:55:45 +03:00
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+");
}
2016-09-22 18:01:10 +03:00
/**
* 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));
}
2016-09-22 17:55:45 +03:00
}