code: public static byte[] toNullTerminatedFixedSizeByteArray(String s, int length) {
          if (s.length() >= length) {
              s = s.substring(0, length - 1);
          }
          while (s.length() < length) {
              s += '\0';
          }
          return s.getBytes();
      }
docs: Converts a string to a null-terminated fixed size byte array.
  
  @param s string to convert
  @param length size of the byte array to return
  @return byte array of specified length containing the string s null-terminated