@@ -142,7 +142,7 @@ public static String toSmartDecode(String value, TransUtil.EncodePattern encodeP
142142 // URL encode match
143143 switch (encodePattern ) {
144144 case URL_STANDARD : {
145- String guessCode = (charset == null ) ? HttpUtil . getGuessCode (Util .getRawByte (TransUtil .decodeUrl (value , "8859_1" ))) : charset ;
145+ String guessCode = (charset == null ) ? getUniversalGuessCode (Util .getRawByte (TransUtil .decodeUrl (value , "8859_1" ))) : charset ;
146146 if (guessCode != null ) {
147147 applyCharset = guessCode ;
148148 decode = TransUtil .decodeUrl (value , guessCode );
@@ -161,7 +161,7 @@ public static String toSmartDecode(String value, TransUtil.EncodePattern encodeP
161161 break ;
162162 // Byte
163163 case BYTE : {
164- String guessCode = (charset == null ) ? HttpUtil . getGuessCode (Util .getRawByte (toByteDecode (value , "8859_1" ))) : charset ;
164+ String guessCode = (charset == null ) ? getUniversalGuessCode (Util .getRawByte (toByteDecode (value , "8859_1" ))) : charset ;
165165 if (guessCode != null ) {
166166 applyCharset = guessCode ;
167167 decode = toByteDecode (value , applyCharset );
@@ -172,7 +172,7 @@ public static String toSmartDecode(String value, TransUtil.EncodePattern encodeP
172172 break ;
173173 // uuencode
174174 case UUENCODE : {
175- String guessCode = (charset == null ) ? HttpUtil . getGuessCode (Util .getRawByte (toUudecode (value , "8859_1" ))) : charset ;
175+ String guessCode = (charset == null ) ? getUniversalGuessCode (Util .getRawByte (toUudecode (value , "8859_1" ))) : charset ;
176176 if (guessCode != null ) {
177177 applyCharset = guessCode ;
178178 decode = toUudecode (value , guessCode );
@@ -183,7 +183,7 @@ public static String toSmartDecode(String value, TransUtil.EncodePattern encodeP
183183 break ;
184184 // QuotedPrintable
185185 case QUOTEDPRINTABLE : {
186- String guessCode = (charset == null ) ? HttpUtil . getGuessCode (Util .getRawByte (toUudecode (value , "8859_1" ))) : charset ;
186+ String guessCode = (charset == null ) ? getUniversalGuessCode (Util .getRawByte (toUudecode (value , "8859_1" ))) : charset ;
187187 if (guessCode != null ) {
188188 applyCharset = guessCode ;
189189 decode = toUnQuotedPrintable (value , guessCode );
@@ -196,7 +196,7 @@ public static String toSmartDecode(String value, TransUtil.EncodePattern encodeP
196196 case BASE64 : {
197197 value = value .replaceAll ("[\r \n ]" , "" ); // 改行削除
198198 byte [] bytes = DatatypeConverter .parseBase64Binary (value );
199- String guessCode = (charset == null ) ? HttpUtil . getGuessCode (bytes ) : charset ;
199+ String guessCode = (charset == null ) ? getUniversalGuessCode (bytes ) : charset ;
200200 if (guessCode != null ) {
201201 applyCharset = guessCode ;
202202 decode = ConvertUtil .toBase64Decode (value , guessCode );
@@ -1168,6 +1168,10 @@ public static void hexDump(byte[] output, PrintStream out) {
11681168 }
11691169 }
11701170
1171+ public static String getUniversalGuessCode (byte [] bytes ) {
1172+ return getUniversalGuessCode (bytes , null );
1173+ }
1174+
11711175 /**
11721176 *
11731177 * @param bytes 文字コードを調べるデータ
@@ -1192,7 +1196,7 @@ public static String getUniversalGuessCode(byte[] bytes, String defaultCharset)
11921196 if (guessCharset == null ) {
11931197 guessCharset = defaultCharset ;
11941198 }
1195- return guessCharset ;
1199+ return normalizeCharset ( guessCharset ) ;
11961200 }
11971201
11981202 private final static Map <String , String > CHARSET_ALIAS = new HashMap ();
0 commit comments