code: public static byte[] str2UnicodeByteArray(final JBBPByteOrder byteOrder, final String str) {
      final byte[] result = new byte[str.length() << 1];
      int index = 0;
      for (int i = 0; i < str.length(); i++) {
        final int val = str.charAt(i);
        switch (byteOrder) {
          case BIG_ENDIAN: {
            result[index++] = (byte) (val >> 8);
            result[index++] = (byte) val;
          }
          break;
          case LITTLE_ENDIAN: {
            result[index++] = (byte) val;
            result[index++] = (byte) (val >> 8);
          }
          break;
          default:
            throw new Error("Unexpected byte order [" + byteOrder + ']');
        }
      }
      return result;
    }
docs: Convert chars of a string into a byte array contains the unicode codes.
  
  @param byteOrder the byte order for the operation, must not be null
  @param str       the string which chars should be written, must not be null
  @return the byte array contains unicodes of the string written as byte
  pairs
  @since 1.1