@@ -75,7 +75,7 @@ public static ChronoUnit toChronoUnit(DateUnit unit) {
7575 }
7676
7777 public enum EncodeType {
78- ALL , ALPHANUM , STANDARD , LIGHT , URL_SAFE , JAVA_SCRIPT
78+ ALL , ALPHANUM , STANDARD , LIGHT , BURP_LIKE , JAVA_SCRIPT
7979 };
8080
8181 public enum ConvertCase {
@@ -92,8 +92,8 @@ public static Pattern getEncodeTypePattern(EncodeType type) {
9292 return SmartCodec .ENCODE_PATTERN_STANDARD ;
9393 case LIGHT :
9494 return SmartCodec .ENCODE_PATTERN_LIGHT ;
95- case URL_SAFE :
96- return SmartCodec .ENCODE_PATTERN_URLSAFE ;
95+ case BURP_LIKE :
96+ return SmartCodec .ENCODE_PATTERN_BURP ;
9797 case JAVA_SCRIPT :
9898 return SmartCodec .ENCODE_PATTERN_JS ;
9999 default :
@@ -959,116 +959,104 @@ public static String toByteOctEncode(byte[] bytes, Pattern pattern) {
959959
960960 private final static Pattern PTN_BYTE_GROUP = Pattern .compile ("((?:\\ \\ [xX][0-9a-fA-F]{2})+)|((?:\\ \\ [0-9]{1,3})+)" );
961961
962- public static String toByteDecode (String input , String charset ) {
962+ public static String toByteDecode (String input , String charset ) throws UnsupportedEncodingException {
963963 StringBuffer buff = new StringBuffer ();
964964 Matcher m = PTN_BYTE_GROUP .matcher (input );
965- try {
966- while (m .find ()) {
967- String hex = m .group (1 );
968- String oct = m .group (2 );
969- if (hex != null ) {
970- Matcher m2 = PTN_BYTE_HEX1 .matcher (hex );
971- ByteBuffer buf = ByteBuffer .allocate (hex .length ());
972- while (m2 .find ()) {
973- String hexcode = m2 .group (1 );
974- int u = Character .digit (hexcode .charAt (0 ), 16 );
975- int l = Character .digit (hexcode .charAt (1 ), 16 );
976- buf .put ((byte ) ((u << 4 ) + l ));
977- }
978- buf .flip ();
979- byte [] value = new byte [buf .limit ()];
980- buf .get (value );
981- m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
982- } else if (oct != null ) {
983- Matcher m3 = PTN_BYTE_OCT .matcher (oct );
984- ByteBuffer buf = ByteBuffer .allocate (oct .length ());
985- while (m3 .find ()) {
986- String octecode = m3 .group (1 );
987- buf .put ((byte ) Integer .parseInt (octecode , 8 ));
988- }
989- buf .flip ();
990- byte [] value = new byte [buf .limit ()];
991- buf .get (value );
992- m .appendReplacement (buff , Matcher .quoteReplacement (new String (value , charset )));
965+ while (m .find ()) {
966+ String hex = m .group (1 );
967+ String oct = m .group (2 );
968+ if (hex != null ) {
969+ Matcher m2 = PTN_BYTE_HEX1 .matcher (hex );
970+ ByteBuffer buf = ByteBuffer .allocate (hex .length ());
971+ while (m2 .find ()) {
972+ String hexcode = m2 .group (1 );
973+ int u = Character .digit (hexcode .charAt (0 ), 16 );
974+ int l = Character .digit (hexcode .charAt (1 ), 16 );
975+ buf .put ((byte ) ((u << 4 ) + l ));
976+ }
977+ buf .flip ();
978+ byte [] value = new byte [buf .limit ()];
979+ buf .get (value );
980+ m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
981+ } else if (oct != null ) {
982+ Matcher m3 = PTN_BYTE_OCT .matcher (oct );
983+ ByteBuffer buf = ByteBuffer .allocate (oct .length ());
984+ while (m3 .find ()) {
985+ String octecode = m3 .group (1 );
986+ buf .put ((byte ) Integer .parseInt (octecode , 8 ));
993987 }
988+ buf .flip ();
989+ byte [] value = new byte [buf .limit ()];
990+ buf .get (value );
991+ m .appendReplacement (buff , Matcher .quoteReplacement (new String (value , charset )));
994992 }
995- m .appendTail (buff );
996- } catch (UnsupportedEncodingException ex ) {
997- logger .log (Level .SEVERE , ex .getMessage (), ex );
998993 }
994+ m .appendTail (buff );
999995 return buff .toString ();
1000996 }
1001997 private final static Pattern PTN_BYTE_HEX = Pattern .compile ("((?:[0-9a-fA-F]{2}))" );
1002998
1003- public static String toByteHexDecode (String input , String charset ) {
999+ public static String toByteHexDecode (String input , String charset ) throws UnsupportedEncodingException {
10041000 StringBuffer buff = new StringBuffer ();
10051001 Matcher m = PTN_BYTE_HEX_GROUP .matcher (input );
1006- try {
1007- while (m .find ()) {
1008- String hex = m .group (1 );
1009- if (hex != null ) {
1010- Matcher m0 = PTN_BYTE_HEX .matcher (hex );
1011- ByteBuffer buf = ByteBuffer .allocate (hex .length ());
1012- while (m0 .find ()) {
1013- String hexcode = m0 .group (1 );
1014- int u = Character .digit (hexcode .charAt (0 ), 16 );
1015- int l = Character .digit (hexcode .charAt (1 ), 16 );
1016- buf .put ((byte ) ((u << 4 ) + l ));
1017- }
1018- buf .flip ();
1019- byte [] value = new byte [buf .limit ()];
1020- buf .get (value );
1021- m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
1002+ while (m .find ()) {
1003+ String hex = m .group (1 );
1004+ if (hex != null ) {
1005+ Matcher m0 = PTN_BYTE_HEX .matcher (hex );
1006+ ByteBuffer buf = ByteBuffer .allocate (hex .length ());
1007+ while (m0 .find ()) {
1008+ String hexcode = m0 .group (1 );
1009+ int u = Character .digit (hexcode .charAt (0 ), 16 );
1010+ int l = Character .digit (hexcode .charAt (1 ), 16 );
1011+ buf .put ((byte ) ((u << 4 ) + l ));
10221012 }
1013+ buf .flip ();
1014+ byte [] value = new byte [buf .limit ()];
1015+ buf .get (value );
1016+ m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
10231017 }
1024- m .appendTail (buff );
1025- } catch (UnsupportedEncodingException ex ) {
1026- logger .log (Level .SEVERE , ex .getMessage (), ex );
10271018 }
1019+ m .appendTail (buff );
10281020 return buff .toString ();
10291021 }
10301022
10311023 private final static Pattern PTN_BYTE_HEX2_GROUP = Pattern .compile ("((?:\\ \\ [xX][0-9a-fA-F]{2})+)|((?:\\ \\ [0-9a-fA-F]{2})+)" );
10321024
1033- public static String toByteHex2Decode (String input , String charset ) {
1025+ public static String toByteHex2Decode (String input , String charset ) throws UnsupportedEncodingException {
10341026 StringBuffer buff = new StringBuffer ();
10351027 Matcher m = PTN_BYTE_HEX2_GROUP .matcher (input );
1036- try {
1037- while (m .find ()) {
1038- String hex1 = m .group (1 );
1039- String hex2 = m .group (2 );
1040- if (hex1 != null ) {
1041- Matcher m2 = PTN_BYTE_HEX1 .matcher (hex1 );
1042- ByteBuffer buf = ByteBuffer .allocate (hex1 .length ());
1043- while (m2 .find ()) {
1044- String hexcode = m2 .group (1 );
1045- int u = Character .digit (hexcode .charAt (0 ), 16 );
1046- int l = Character .digit (hexcode .charAt (1 ), 16 );
1047- buf .put ((byte ) ((u << 4 ) + l ));
1048- }
1049- buf .flip ();
1050- byte [] value = new byte [buf .limit ()];
1051- buf .get (value );
1052- m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
1053- } else if (hex2 != null ) {
1054- Matcher m3 = PTN_BYTE_HEX2 .matcher (hex2 );
1055- ByteBuffer buf = ByteBuffer .allocate (hex2 .length ());
1056- while (m3 .find ()) {
1057- String hexcode = m3 .group (1 );
1058- int u = Character .digit (hexcode .charAt (0 ), 16 );
1059- int l = Character .digit (hexcode .charAt (1 ), 16 );
1060- buf .put ((byte ) ((u << 4 ) + l ));
1061- }
1062- buf .flip ();
1063- byte [] value = new byte [buf .limit ()];
1064- buf .get (value );
1065- m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
1028+ while (m .find ()) {
1029+ String hex1 = m .group (1 );
1030+ String hex2 = m .group (2 );
1031+ if (hex1 != null ) {
1032+ Matcher m2 = PTN_BYTE_HEX1 .matcher (hex1 );
1033+ ByteBuffer buf = ByteBuffer .allocate (hex1 .length ());
1034+ while (m2 .find ()) {
1035+ String hexcode = m2 .group (1 );
1036+ int u = Character .digit (hexcode .charAt (0 ), 16 );
1037+ int l = Character .digit (hexcode .charAt (1 ), 16 );
1038+ buf .put ((byte ) ((u << 4 ) + l ));
1039+ }
1040+ buf .flip ();
1041+ byte [] value = new byte [buf .limit ()];
1042+ buf .get (value );
1043+ m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
1044+ } else if (hex2 != null ) {
1045+ Matcher m3 = PTN_BYTE_HEX2 .matcher (hex2 );
1046+ ByteBuffer buf = ByteBuffer .allocate (hex2 .length ());
1047+ while (m3 .find ()) {
1048+ String hexcode = m3 .group (1 );
1049+ int u = Character .digit (hexcode .charAt (0 ), 16 );
1050+ int l = Character .digit (hexcode .charAt (1 ), 16 );
1051+ buf .put ((byte ) ((u << 4 ) + l ));
10661052 }
1053+ buf .flip ();
1054+ byte [] value = new byte [buf .limit ()];
1055+ buf .get (value );
1056+ m .appendReplacement (buff , Matcher .quoteReplacement (StringUtil .getStringCharset (value , charset )));
10671057 }
1068- m .appendTail (buff );
1069- } catch (UnsupportedEncodingException ex ) {
1070- logger .log (Level .SEVERE , ex .getMessage (), ex );
10711058 }
1059+ m .appendTail (buff );
10721060 return buff .toString ();
10731061 }
10741062
0 commit comments