Added support for binDecode

This commit is contained in:
Shekhar Gulati
2016-05-16 18:46:41 +05:30
parent 9ce0b2287c
commit 6ab8d2dab2
2 changed files with 29 additions and 0 deletions
+17
View File
@@ -7,6 +7,8 @@ import java.util.StringJoiner;
import java.util.function.Predicate;
import java.util.function.Supplier;
import static java.util.stream.Collectors.joining;
/**
* A String manipulation library without any dependencies
*/
@@ -317,6 +319,21 @@ public abstract class Strman {
return Base64.getEncoder().encodeToString(value.getBytes());
}
/**
* Convert binary unicode (16 digits) string to string chars
*
* @param value The value to decode
* @return The decoded String
*/
public static String binDecode(final String value) {
validate(value, NULL_STRING_PREDICATE, NULL_STRING_MSG_SUPPLIER);
return Arrays
.stream(value.split("(?<=\\G.{16})"))
.map(data -> String.valueOf(Character.toChars(Integer.parseInt(data,2))))
.collect(joining());
}
private static long countSubstr(String value, String subStr, boolean allowOverlapping, long count) {
int position = value.indexOf(subStr);
if (position == -1) {