代码: /** * Write the String data * * @param out * @param value */ public static void writeUnicode(final DataOutputStream out, final String value) throws ActionException { try { final String unicode = StringFormatter.gbEncoding( value ); final byte[] data = unicode.getBytes(); final int dataLength = data.length;
System.out.PRintln( "Data Length is: " + dataLength ); System.out.println( "Data is: " + value ); out.writeInt( dataLength ); out.write( data, 0, dataLength ); } catch (IOException e) { throw new ActionException( IMDefaultAction.class.getName(), e.getMessage() ); } } 以下代码是gbEncoding()方法,把双字节字符转换成/uXXXX,ASIIC码在前面补00。
/** * This method will encode the String to unicode. * * @param gbString * @return */