@Test public void testencodeBytes() throws UnsupportedEncodingException { String str = "中文"; System.out.println(new String(ConvertUtil.encodeBytes(str.getBytes(Opslab.GBK), ' '))); System.out.println(new String(ConvertUtil.encodeBytes(str.getBytes(Opslab.UTF_8), ' '))); }
public final static byte[] encodeBytes(byte[] source, char split) { ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } bos.write(split); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); bos.write(hex1); bos.write(hex2); } return bos.toByteArray(); }
ConvertUtil { public final static byte[] encodeBytes(byte[] source, char split) { ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } bos.write(split); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); bos.write(hex1); bos.write(hex2); } return bos.toByteArray(); } }
ConvertUtil { public final static byte[] encodeBytes(byte[] source, char split) { ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } bos.write(split); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); bos.write(hex1); bos.write(hex2); } return bos.toByteArray(); }  }
ConvertUtil { public final static byte[] encodeBytes(byte[] source, char split) { ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } bos.write(split); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); bos.write(hex1); bos.write(hex2); } return bos.toByteArray(); }  final static byte[] shortToByte(short number); final static short byteToShort(byte[] b); final static byte[] intToByte(int i); final static byte[] intToByte(int[] arr); final static byte[] encodeBytes(byte[] source, char split); final static char[] bytesToChars(byte[] bytes); final static int bytesToInt(byte[] bytes); final static byte[] longToByte(long number); final static long byteToLong(byte[] b); final static String byteToBinary(byte src); final static String hexStringtoBinarg(String hexStr); final static String bytesToHexString(byte[] bytes); final static byte[] hexStringToByte(String hexString); }
ConvertUtil { public final static byte[] encodeBytes(byte[] source, char split) { ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } bos.write(split); char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); bos.write(hex1); bos.write(hex2); } return bos.toByteArray(); }  final static byte[] shortToByte(short number); final static short byteToShort(byte[] b); final static byte[] intToByte(int i); final static byte[] intToByte(int[] arr); final static byte[] encodeBytes(byte[] source, char split); final static char[] bytesToChars(byte[] bytes); final static int bytesToInt(byte[] bytes); final static byte[] longToByte(long number); final static long byteToLong(byte[] b); final static String byteToBinary(byte src); final static String hexStringtoBinarg(String hexStr); final static String bytesToHexString(byte[] bytes); final static byte[] hexStringToByte(String hexString);  }