当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequests类代码示例

本文整理汇总了Java中com.intellij.util.io.HttpRequests的典型用法代码示例。如果您正苦于以下问题:Java HttpRequests类的具体用法?Java HttpRequests怎么用?Java HttpRequests使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequests类属于com.intellij.util.io包,在下文中一共展示了HttpRequests类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updateIcon

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
public void updateIcon() {
  myUserIcon = null;

  String email = myState.email;
  if (email == null) {
    myState.iconBytes = null;
    return;
  }

  // get node size
  int size = AllIcons.Actions.Find.getIconHeight();
  ApplicationManager.getApplication().executeOnPooledThread(() -> {
    String emailHash = DigestUtils.md5Hex(email.toLowerCase().trim());

    try {
      byte[] bytes = HttpRequests.request("https://www.gravatar.com/avatar/" + emailHash + ".png?s=" + size + "&d=identicon").readBytes(null);

      myState.iconBytes = Base64.getEncoder().encodeToString(bytes);
    }
    catch (IOException e) {
      LOGGER.error(e);
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:ServiceAuthConfiguration.java

示例2: downloadPlugin

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
private File downloadPlugin(final ProgressIndicator indicator) throws IOException {
  File pluginsTemp = new File(PathManager.getPluginTempPath());
  if (!pluginsTemp.exists() && !pluginsTemp.mkdirs()) {
    throw new IOException(IdeBundle.message("error.cannot.create.temp.dir", pluginsTemp));
  }
  final File file = FileUtil.createTempFile(pluginsTemp, "plugin_", "_download", true, false);

  indicator.checkCanceled();
  if (myIsPlatform) {
    indicator.setText2(IdeBundle.message("progress.downloading.platform"));
  }
  else {
    indicator.setText2(IdeBundle.message("progress.downloading.plugin", getPluginName()));
  }

  return HttpRequests.request(myPluginUrl).gzip(false).connect(request -> {
    request.saveToFile(file, indicator);

    String fileName = getFileName();
    File newFile = new File(file.getParentFile(), fileName);
    FileUtil.rename(file, newFile);
    return newFile;
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:PluginDownloader.java

示例3: call

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
@Override
public String call() throws Exception {
  logger.debug("About to fetch experiments.");
  return HttpRequests.request(
          System.getProperty(EXPERIMENTS_URL_PROPERTY, DEFAULT_EXPERIMENT_URL) + pluginName)
      .readString(/* progress indicator */ null);
}
 
开发者ID:bazelbuild,项目名称:intellij,代码行数:8,代码来源:WebExperimentSyncer.java

示例4: perform

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
@Override
public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
  final ActionCallback callback = new ActionCallback();
  Task task = new Task.Backgroundable(myProject, "Downloading Sources", true) {
    @Override
    public void run(@NotNull final ProgressIndicator indicator) {
      final byte[] bytes;
      try {
        LOG.info("Downloading sources JAR: " + myUrl);
        indicator.checkCanceled();
        bytes = HttpRequests.request(myUrl).readBytes(indicator);
      }
      catch (IOException e) {
        LOG.warn(e);
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            new Notification(myMessageGroupId,
                             "Downloading failed",
                             "Failed to download sources: " + myUrl,
                             NotificationType.ERROR)
              .notify(getProject());

            callback.setDone();
          }
        });
        return;
      }

      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          AccessToken accessToken = WriteAction.start();
          try {
            storeFile(bytes);
          }
          finally {
            accessToken.finish();
            callback.setDone();
          }
        }
      });
    }

    @Override
    public void onCancel() {
      callback.setRejected();
    }
  };

  task.queue();

  return callback;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:55,代码来源:AbstractAttachSourceProvider.java

示例5: getIssuesFromRepositories

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
@Nullable
private List<Task> getIssuesFromRepositories(@Nullable String request, int offset, int limit, boolean withClosed, boolean forceRequest, @NotNull final ProgressIndicator cancelled)
{
	List<Task> issues = null;
	for(final TaskRepository repository : getAllRepositories())
	{
		if(!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository)))
		{
			continue;
		}
		try
		{
			long start = System.currentTimeMillis();
			Task[] tasks = repository.getIssues(request, offset, limit, withClosed, cancelled);
			long timeSpent = System.currentTimeMillis() - start;
			LOG.info(String.format("Total %s ms to download %d issues from '%s' (pattern '%s')", timeSpent, tasks.length, repository.getUrl(), request));
			myBadRepositories.remove(repository);
			if(issues == null)
			{
				issues = new ArrayList<>(tasks.length);
			}
			if(!repository.isSupported(TaskRepository.NATIVE_SEARCH) && request != null)
			{
				List<Task> filteredTasks = TaskSearchSupport.filterTasks(request, ContainerUtil.list(tasks));
				ContainerUtil.addAll(issues, filteredTasks);
			}
			else
			{
				ContainerUtil.addAll(issues, tasks);
			}
		}
		catch(ProcessCanceledException ignored)
		{
			// OK
		}
		catch(Exception e)
		{
			String reason = "";
			// Fix to IDEA-111810
			//noinspection InstanceofCatchParameter
			if(e.getClass() == Exception.class || e instanceof RequestFailedException)
			{
				// probably contains some message meaningful to end-user
				reason = e.getMessage();
			}
			//noinspection InstanceofCatchParameter
			if(e instanceof SocketTimeoutException || e instanceof HttpRequests.HttpStatusException)
			{
				LOG.warn("Can't connect to " + repository + ": " + e.getMessage());
			}
			else
			{
				LOG.warn("Cannot connect to " + repository, e);
			}
			myBadRepositories.add(repository);
			if(forceRequest)
			{
				notifyAboutConnectionFailure(repository, reason);
			}
		}
	}
	return issues;
}
 
开发者ID:consulo,项目名称:consulo-tasks,代码行数:64,代码来源:TaskManagerImpl.java

示例6: configureCheckButton

import com.intellij.util.io.HttpRequests; //导入依赖的package包/类
private void configureCheckButton() {
  if (HttpConfigurable.getInstance() == null) {
    myCheckButton.setVisible(false);
    return;
  }

  myCheckButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(@Nonnull ActionEvent e) {
      final String title = "Check Proxy Settings";
      final String answer = Messages.showInputDialog(myMainPanel, "Warning: your settings will be saved.\n\nEnter any URL to check connection to:",
                                                     title, Messages.getQuestionIcon(), "http://", null);
      if (StringUtil.isEmptyOrSpaces(answer)) {
        return;
      }

      final HttpConfigurable settings = HttpConfigurable.getInstance();
      apply(settings);
      final AtomicReference<IOException> exceptionReference = new AtomicReference<>();
      myCheckButton.setEnabled(false);
      myCheckButton.setText("Check connection (in progress...)");
      myConnectionCheckInProgress = true;
      ApplicationManager.getApplication().executeOnPooledThread(() -> {
        try {
          //already checked for null above
          //noinspection ConstantConditions
          HttpRequests.request(answer)
                  .readTimeout(3 * 1000)
                  .tryConnect();
        }
        catch (IOException e1) {
          exceptionReference.set(e1);
        }

        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> {
          myConnectionCheckInProgress = false;
          reset(settings);  // since password might have been set
          Component parent;
          if (myMainPanel.isShowing()) {
            parent = myMainPanel;
            myCheckButton.setText("Check connection");
            myCheckButton.setEnabled(canEnableConnectionCheck());
          }
          else {
            IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
            if (frame == null) {
              return;
            }
            parent = frame.getComponent();
          }
          //noinspection ThrowableResultOfMethodCallIgnored
          final IOException exception = exceptionReference.get();
          if (exception == null) {
            Messages.showMessageDialog(parent, "Connection successful", title, Messages.getInformationIcon());
          }
          else {
            final String message = exception.getMessage();
            if (settings.USE_HTTP_PROXY) {
              settings.LAST_ERROR = message;
            }
            Messages.showErrorDialog(parent, errorText(message));
          }
        });
      });
    }
  });
}
 
开发者ID:consulo,项目名称:consulo,代码行数:69,代码来源:HttpProxySettingsUi.java


注:本文中的com.intellij.util.io.HttpRequests类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。