code: private byte[] getBytes(String value, boolean unicode)
     {
        byte[] result;
        if (unicode)
        {
           int start = 0;
           // Get the bytes in UTF-16
           byte[] bytes;
  
           try
           {
              bytes = value.getBytes("UTF-16");
           }
           catch (UnsupportedEncodingException e)
           {
              bytes = value.getBytes();
           }
  
           if (bytes.length > 2 && bytes[0] == -2 && bytes[1] == -1)
           {
              // Skip the unicode identifier
              start = 2;
           }
           result = new byte[bytes.length - start];
           for (int loop = start; loop < bytes.length - 1; loop += 2)
           {
              // Swap the order here
              result[loop - start] = bytes[loop + 1];
              result[loop + 1 - start] = bytes[loop];
           }
        }
        else
        {
           result = new byte[value.length() + 1];
           System.arraycopy(value.getBytes(), 0, result, 0, value.length());
        }
        return (result);
     }
docs: Convert a Java String instance into the equivalent array of single or
  double bytes.
  
  @param value Java String instance representing text
  @param unicode true if double byte characters are required
  @return byte array representing the supplied text