code: public void set(String string, boolean optimized) {
      int len = string.length();
      if (len > 0xffff/3) {             // maybe too long
        LOG.warn("truncating long string: " + string.length()
                 + " chars, starting with " + string.substring(0, 20));
        string = string.substring(0, 0xffff/3);
        len = string.length();
      }
      
      if (optimized) {
        // speculate that we can do fast conversion
        char[] charArray = getCharArray(len);
        length = len;
        if (bytes == null || length > bytes.length) // grow buffer
          bytes = new byte[length];
        
        if (copyStringToBytes(string, charArray, bytes, len))
          // done, length is set
          // bytes are already copied
          return;
      }
      
      // we need to do full conversion
      length = utf8Length(string);                  // compute length
      if (length > 0xffff)                          // double-check length
        throw new RuntimeException("string too long!");
  
      if (bytes == null || length > bytes.length)   // grow buffer
        bytes = new byte[length];
  
      try {                                         // avoid sync'd allocations
        writeChars(bytes, string, 0, string.length());
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
docs: Set to contain the contents of a string.
  @param optimize - optimize for setting ASCII strings.