| | |
| | | |
| | | import javax.xml.bind.DatatypeConverter; |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.ByteBuffer; |
| | | import java.util.zip.CRC32; |
| | | |
| | |
| | | **/ |
| | | public class ByteUtils { |
| | | /** |
| | | * byte数组转中文字符串 |
| | | */ |
| | | public static String bytesToStringZh(byte[] bytes) { |
| | | String zhStr = ""; |
| | | try { |
| | | int position = ByteUtils.findIndexOfDoubleZero(bytes); |
| | | if (position != -1) { |
| | | byte[] result = new byte[position]; |
| | | System.arraycopy(bytes, 0, result, 0, position); |
| | | zhStr = new String(result, "GBK"); |
| | | } else { |
| | | zhStr = new String(bytes, "GBK"); |
| | | } |
| | | } catch (UnsupportedEncodingException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return zhStr; |
| | | } |
| | | |
| | | /** |
| | | * Byte字节转Hex |
| | | * |
| | | * @param b 字节 |