code: private static byte[] toByteArray(String string) {
          byte[] bytes = new byte[string.length() + 1];
          for (int i = 0; i < string.length(); i++) {
              bytes[i] = (byte) string.charAt(i);
          }
          return bytes;
      }
docs: Conversion of strings to/from null-terminated byte arrays.
  
  @param string String to convert to null-terminated byte array.
  @return Null-terminated byte array.