Here you can find the source of convertToUnicodeByteArray(String s)
Parameter | Description |
---|---|
s | the string to convert |
public static byte[] convertToUnicodeByteArray(String s)
//package com.java2s; public class Main { /**/*w w w . j a v a 2 s.c o m*/ * Converts the String to a UNICODE byte array. It will also add the ending * null characters to the end of the string. * @param s the string to convert * @return the unicode byte array of the string */ public static byte[] convertToUnicodeByteArray(String s) { if (s == null) { return null; } char c[] = s.toCharArray(); byte[] result = new byte[(c.length * 2) + 2]; for (int i = 0; i < c.length; i++) { result[(i * 2)] = (byte) (c[i] >> 8); result[((i * 2) + 1)] = (byte) c[i]; } // Add the UNICODE null character result[result.length - 2] = 0; result[result.length - 1] = 0; return result; } }