作者 tzg

解决 Byte[] 类型 to string 死循环的问题

@@ -7,6 +7,7 @@ import java.nio.charset.Charset; @@ -7,6 +7,7 @@ import java.nio.charset.Charset;
7 import java.text.NumberFormat; 7 import java.text.NumberFormat;
8 import java.util.Set; 8 import java.util.Set;
9 import com.ruoyi.common.utils.StringUtils; 9 import com.ruoyi.common.utils.StringUtils;
  10 +import org.apache.commons.lang3.ArrayUtils;
10 11
11 /** 12 /**
12 * 类型转换器 13 * 类型转换器
@@ -784,23 +785,19 @@ public class Convert @@ -784,23 +785,19 @@ public class Convert
784 * @param charset 字符集 785 * @param charset 字符集
785 * @return 字符串 786 * @return 字符串
786 */ 787 */
787 - public static String str(Object obj, Charset charset)  
788 - {  
789 - if (null == obj)  
790 - { 788 + public static String str(Object obj, Charset charset) {
  789 + if (null == obj) {
791 return null; 790 return null;
792 } 791 }
793 792
794 - if (obj instanceof String)  
795 - { 793 + if (obj instanceof String) {
796 return (String) obj; 794 return (String) obj;
797 - }  
798 - else if (obj instanceof byte[] || obj instanceof Byte[])  
799 - {  
800 - return str((Byte[]) obj, charset);  
801 - }  
802 - else if (obj instanceof ByteBuffer)  
803 - { 795 + } else if (obj instanceof byte[]) {
  796 + return str((byte[]) obj, charset);
  797 + } else if (obj instanceof Byte[]) {
  798 + byte[] bytes = ArrayUtils.toPrimitive((Byte[]) obj);
  799 + return str(bytes, charset);
  800 + } else if (obj instanceof ByteBuffer) {
804 return str((ByteBuffer) obj, charset); 801 return str((ByteBuffer) obj, charset);
805 } 802 }
806 return obj.toString(); 803 return obj.toString();