Last active
January 1, 2016 19:09
-
-
Save rickcrawford/8188206 to your computer and use it in GitHub Desktop.
Convert strings with ascii escaped characters to a valid java string. For example \x04 would escape to \n
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.commons.lang.StringEscapeUtils; | |
import org.apache.commons.lang.StringUtils; | |
public class Utils { | |
public static String decodeHex(String str) { | |
if (StringUtils.isBlank(str)) { | |
return str; | |
} | |
return StringEscapeUtils.unescapeJava( | |
str.replaceAll("(?i)\\\\x([0-9a-f]{2})", "\\\\u00$1")) | |
.trim(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment