code: public static void validateKey(final String key, final boolean binary) {
      byte[] keyBytes = KeyUtil.getKeyBytes(key);
      int keyLength = keyBytes.length;
  
      if (keyLength > MAX_KEY_LENGTH) {
        throw KEY_TOO_LONG_EXCEPTION;
      }
  
      if (keyLength == 0) {
        throw KEY_EMPTY_EXCEPTION;
      }
  
      if(!binary) {
        for (byte b : keyBytes) {
          if (b == ' ' || b == '\n' || b == '\r' || b == 0) {
            throw new IllegalArgumentException(
                "Key contains invalid characters:  ``" + key + "''");
          }
        }
      }
  
    }
docs: Check if a given key is valid to transmit.
  
  @param key the key to check.
  @param binary if binary protocol is used.