• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java NetUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: writeLine

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@SuppressWarnings({"SocketOpenedButNotSafelyClosed", "IOResourceOpenedButNotSafelyClosed"})
private synchronized void writeLine(@NonNls final String s) {
  if (myWriter == null) {
    try {
      if (mySocket == null) {
        mySocket = new Socket(NetUtils.getLoopbackAddress(), myPortNumber);
      }
      myWriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mySocket.getOutputStream())));
    }
    catch (IOException e) {
      return;
    }
  }
  myWriter.println(s);
  myWriter.flush();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ProcessProxyImpl.java


示例2: getJavacManager

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Nullable
private ExternalJavacManager getJavacManager() throws IOException {
  ExternalJavacManager manager = myExternalJavacManager;
  if (manager == null) {
    synchronized (this) {
      manager = myExternalJavacManager;
      if (manager == null) {
        final File compilerWorkingDir = getJavacCompilerWorkingDir();
        if (compilerWorkingDir == null) {
          return null; // should not happen for real projects
        }
        final int listenPort = NetUtils.findAvailableSocketPort();
        manager = new ExternalJavacManager(compilerWorkingDir);
        manager.start(listenPort);
        myExternalJavacManager = manager;
      }
    }
  }
  return manager;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CompilerManagerImpl.java


示例3: startListening

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
private int startListening() throws Exception {
  final ServerBootstrap bootstrap = NettyUtil.nioServerBootstrap(new NioEventLoopGroup(1, PooledThreadExecutor.INSTANCE));
  bootstrap.childHandler(new ChannelInitializer() {
    @Override
    protected void initChannel(Channel channel) throws Exception {
      channel.pipeline().addLast(myChannelRegistrar,
                                 new ProtobufVarint32FrameDecoder(),
                                 new ProtobufDecoder(CmdlineRemoteProto.Message.getDefaultInstance()),
                                 new ProtobufVarint32LengthFieldPrepender(),
                                 new ProtobufEncoder(),
                                 myMessageDispatcher);
    }
  });
  Channel serverChannel = bootstrap.bind(NetUtils.getLoopbackAddress(), 0).syncUninterruptibly().channel();
  myChannelRegistrar.add(serverChannel);
  return ((InetSocketAddress)serverChannel.localAddress()).getPort();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:BuildManager.java


示例4: MyRunnableState

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
public MyRunnableState(@NotNull ExternalSystemTaskExecutionSettings settings,
                       @NotNull Project project,
                       boolean debug,
                       @NotNull ExternalSystemRunConfiguration configuration,
                       @NotNull ExecutionEnvironment env) {
  mySettings = settings;
  myProject = project;
  myConfiguration = configuration;
  myEnv = env;
  int port;
  if (debug) {
    try {
      port = NetUtils.findAvailableSocketPort();
    }
    catch (IOException e) {
      LOG.warn("Unexpected I/O exception occurred on attempt to find a free port to use for external system task debugging", e);
      port = 0;
    }
  }
  else {
    port = 0;
  }
  myDebugPort = port;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ExternalSystemRunConfiguration.java


示例5: apply

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Override
public void apply() throws ConfigurationException {
  if (myPanel.myUseSecureConnection.isSelected() && !NetUtils.isSniEnabled()) {
    boolean tooOld = !SystemInfo.isJavaVersionAtLeast("1.7");
    String message = IdeBundle.message(tooOld ? "update.sni.not.available.error" : "update.sni.disabled.error");
    throw new ConfigurationException(message);
  }

  boolean wasEnabled = mySettings.isCheckNeeded();
  mySettings.setCheckNeeded(myPanel.myCheckForUpdates.isSelected());
  if (wasEnabled != mySettings.isCheckNeeded()) {
    UpdateCheckerComponent checker = ApplicationManager.getApplication().getComponent(UpdateCheckerComponent.class);
    if (checker != null) {
      if (wasEnabled) {
        checker.cancelChecks();
      }
      else {
        checker.queueNextCheck();
      }
    }
  }

  mySettings.setUpdateChannelType(myPanel.getSelectedChannelType().getCode());
  mySettings.setSecureConnection(myPanel.myUseSecureConnection.isSelected());
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:UpdateSettingsConfigurable.java


示例6: post

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
private static HttpURLConnection post(URL url, byte[] bytes) throws IOException {
  HttpsURLConnection connection = (HttpsURLConnection)url.openConnection();

  connection.setSSLSocketFactory(ourSslContext.getSocketFactory());
  if (!NetUtils.isSniEnabled()) {
    connection.setHostnameVerifier(new EaHostnameVerifier());
  }

  connection.setRequestMethod("POST");
  connection.setDoInput(true);
  connection.setDoOutput(true);
  connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=" + ENCODING);
  connection.setRequestProperty("Content-Length", Integer.toString(bytes.length));

  OutputStream out = connection.getOutputStream();
  try {
    out.write(bytes);
  }
  finally {
    out.close();
  }

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


示例7: createSocket

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@NotNull
private Socket createSocket() throws IOException {
  InetAddress host = myHost;
  if (host == null) {
    try {
      host = InetAddress.getLocalHost();
    }
    catch (UnknownHostException ignored) {
      host = NetUtils.getLoopbackAddress();
    }
  }

  IOException exc = null;
  for (int i = 0; i < myPortsNumberToTry; i++) {
    int port = myInitialPort + i;
    try {
      return new Socket(host, port);
    }
    catch (IOException e) {
      exc = e;
      LOG.debug(e);
    }
  }
  throw exc;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:SocketConnectionImpl.java


示例8: MyRunnableState

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
public MyRunnableState(@NotNull ExternalSystemTaskExecutionSettings settings, @NotNull Project project, boolean debug) {
  mySettings = settings;
  myProject = project;
  int port;
  if (debug) {
    try {
      port = NetUtils.findAvailableSocketPort();
    }
    catch (IOException e) {
      LOG.warn("Unexpected I/O exception occurred on attempt to find a free port to use for external system task debugging", e);
      port = 0;
    }
  }
  else {
    port = 0;
  }
  myDebugPort = port;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:ExternalSystemRunConfiguration.java


示例9: MyRunnableState

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
public MyRunnableState(@Nonnull ExternalSystemTaskExecutionSettings settings, @Nonnull Project project, boolean debug) {
  mySettings = settings;
  myProject = project;
  int port;
  if (debug) {
    try {
      port = NetUtils.findAvailableSocketPort();
    }
    catch (IOException e) {
      LOG.warn("Unexpected I/O exception occurred on attempt to find a free port to use for external system task debugging", e);
      port = 0;
    }
  }
  else {
    port = 0;
  }
  myDebugPort = port;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:19,代码来源:ExternalSystemRunConfiguration.java


示例10: computeDebugAddress

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@NotNull
@Override
public InetSocketAddress computeDebugAddress() {
  if (host == null) {
    return new InetSocketAddress(NetUtils.getLoopbackAddress(), port);
  }
  else {
    return new InetSocketAddress(host, getPort());
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:11,代码来源:RemoteDebugConfiguration.java


示例11: select

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Override
public List<Proxy> select(@Nullable URI uri) {
  isInstalledAssertion();
  if (uri == null) {
    return NO_PROXY_LIST;
  }
  LOG.debug("CommonProxy.select called for " + uri.toString());

  if (Boolean.TRUE.equals(ourReenterDefence.get())) {
    return NO_PROXY_LIST;
  }
  try {
    ourReenterDefence.set(Boolean.TRUE);
    String host = StringUtil.notNullize(uri.getHost());
    if (NetUtils.isLocalhost(host)) {
      return NO_PROXY_LIST;
    }

    final HostInfo info = new HostInfo(uri.getScheme(), host, correctPortByProtocol(uri));
    final Map<String, ProxySelector> copy;
    synchronized (myLock) {
      if (myNoProxy.contains(Pair.create(info, Thread.currentThread()))) {
        LOG.debug("CommonProxy.select returns no proxy (in no proxy list) for " + uri.toString());
        return NO_PROXY_LIST;
      }
      copy = new THashMap<String, ProxySelector>(myCustom);
    }
    for (Map.Entry<String, ProxySelector> entry : copy.entrySet()) {
      final List<Proxy> proxies = entry.getValue().select(uri);
      if (!ContainerUtil.isEmpty(proxies)) {
        LOG.debug("CommonProxy.select returns custom proxy for " + uri.toString() + ", " + proxies.toString());
        return proxies;
      }
    }
    return NO_PROXY_LIST;
  }
  finally {
    ourReenterDefence.remove();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:CommonProxy.java


示例12: readString

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@NotNull
public String readString(@Nullable final ProgressIndicator indicator) throws IOException {
  return connect(new HttpRequests.RequestProcessor<String>() {
    @Override
    public String process(@NotNull HttpRequests.Request request) throws IOException {
      int contentLength = request.getConnection().getContentLength();
      BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(contentLength > 0 ? contentLength : 16 * 1024);
      NetUtils.copyStreamContent(indicator, request.getInputStream(), out, contentLength);
      return new String(out.getInternalBuffer(), 0, out.size(), HttpRequests.getCharset(request));
    }
  });
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:RequestBuilder.java


示例13: PydevXmlRpcClient

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
/**
 * Constructor (see fields description)
 */
public PydevXmlRpcClient(Process process, int port) throws MalformedURLException {
  XmlRpc.setDefaultInputEncoding("UTF8"); //even though it uses UTF anyway
  impl = new XmlRpcClientLite(NetUtils.getLocalHostString(), port);
  //this.impl = new XmlRpcClient(url, new CommonsXmlRpcTransportFactory(url));
  this.process = process;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PydevXmlRpcClient.java


示例14: findAvailablePorts

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
private static int[] findAvailablePorts(Project project, PyConsoleType consoleType) {
  final int[] ports;
  try {
    // File "pydev/console/pydevconsole.py", line 223, in <module>
    // port, client_port = sys.argv[1:3]
    ports = NetUtils.findAvailableSocketPorts(2);
  }
  catch (IOException e) {
    ExecutionHelper.showErrors(project, Arrays.<Exception>asList(e), consoleType.getTitle(), null);
    return null;
  }
  return ports;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:PydevConsoleRunner.java


示例15: checkAndOpenPage

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
private void checkAndOpenPage(@NotNull final HostAndPort hostAndPort, final int attemptNumber) {
  if (NetUtils.canConnectToRemoteSocket(hostAndPort.getHostText(), hostAndPort.getPort())) {
    openPageNow();
  }
  else {
    LOG.info("[attempt#" + attemptNumber + "] Checking " + hostAndPort + " failed");
    if (!isOutdated()) {
      int delayMillis = getDelayMillis(attemptNumber);
      checkAndOpenPageLater(hostAndPort, attemptNumber + 1, delayMillis);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:BrowserStarter.java


示例16: createJavaParameters

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
  final JavaParameters javaParameters = super.createJavaParameters();
  javaParameters.setupEnvs(getConfiguration().getPersistantData().getEnvs(), getConfiguration().getPersistantData().PASS_PARENT_ENVS);
  javaParameters.setMainClass("org.testng.RemoteTestNGStarter");

  try {
    port = NetUtils.findAvailableSocketPort();
  }
  catch (IOException e) {
    throw new ExecutionException("Unable to bind to port " + port, e);
  }

  final TestData data = getConfiguration().getPersistantData();

  javaParameters.getProgramParametersList().add(supportSerializationProtocol(getConfiguration()) ? RemoteArgs.PORT : CommandLineArgs.PORT, String.valueOf(port));

  if (data.getOutputDirectory() != null && !data.getOutputDirectory().isEmpty()) {
    javaParameters.getProgramParametersList().add(CommandLineArgs.OUTPUT_DIRECTORY, data.getOutputDirectory());
  }

  javaParameters.getProgramParametersList().add(CommandLineArgs.USE_DEFAULT_LISTENERS, String.valueOf(data.USE_DEFAULT_REPORTERS));

  @NonNls final StringBuilder buf = new StringBuilder();
  if (data.TEST_LISTENERS != null && !data.TEST_LISTENERS.isEmpty()) {
    buf.append(StringUtil.join(data.TEST_LISTENERS, ";"));
  }
  collectListeners(javaParameters, buf, IDEATestNGListener.EP_NAME, ";");
  if (buf.length() > 0) javaParameters.getProgramParametersList().add(CommandLineArgs.LISTENER, buf.toString());

  createServerSocket(javaParameters);
  createTempFiles(javaParameters);
  return javaParameters;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:TestNGRunnableState.java


示例17: updateJavaParameters

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Override
public void updateJavaParameters(RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) {
  if (!isApplicableFor(configuration)) {
    return;
  }
  ApplicationConfiguration appConfiguration = (ApplicationConfiguration) configuration;
  SnapShooterConfigurationSettings settings = appConfiguration.getUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY);
  if (settings == null) {
    settings = new SnapShooterConfigurationSettings();
    appConfiguration.putUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY, settings);
  }
  if (appConfiguration.ENABLE_SWING_INSPECTOR) {
    settings.setLastPort(NetUtils.tryToFindAvailableSocketPort());
  }

  if (appConfiguration.ENABLE_SWING_INSPECTOR && settings.getLastPort() != -1) {
    params.getProgramParametersList().prepend(appConfiguration.MAIN_CLASS_NAME);
    params.getProgramParametersList().prepend(Integer.toString(settings.getLastPort()));
    // add +1 because idea_rt.jar will be added as the last entry to the classpath
    params.getProgramParametersList().prepend(Integer.toString(params.getClassPath().getPathList().size() + 1));
    Set<String> paths = new TreeSet<String>();
    paths.add(PathUtil.getJarPathForClass(SnapShooter.class));         // ui-designer-impl
    paths.add(PathUtil.getJarPathForClass(BaseComponent.class));       // appcore-api
    paths.add(PathUtil.getJarPathForClass(ProjectComponent.class));    // openapi
    paths.add(PathUtil.getJarPathForClass(LwComponent.class));         // UIDesignerCore
    paths.add(PathUtil.getJarPathForClass(GridConstraints.class));     // forms_rt
    paths.add(PathUtil.getJarPathForClass(PaletteGroup.class));        // openapi
    paths.add(PathUtil.getJarPathForClass(LafManagerListener.class));  // ui-impl
    paths.add(PathUtil.getJarPathForClass(DataProvider.class));        // action-system-openapi
    paths.add(PathUtil.getJarPathForClass(XmlStringUtil.class));       // idea
    paths.add(PathUtil.getJarPathForClass(Navigatable.class));         // pom
    paths.add(PathUtil.getJarPathForClass(AreaInstance.class));        // extensions
    paths.add(PathUtil.getJarPathForClass(FormLayout.class));          // jgoodies
    paths.addAll(PathManager.getUtilClassPath());
    for(String path: paths) {
      params.getClassPath().addFirst(path);
    }
    params.setMainClass("com.intellij.uiDesigner.snapShooter.SnapShooter");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:41,代码来源:SnapShooterConfigurationExtension.java


示例18: connect

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
@Nullable
private InputStream connect(int port) throws IOException {
    final long s = System.currentTimeMillis();
    final InetSocketAddress endpoint = new InetSocketAddress(NetUtils.getLoopbackAddress(), port);

    myStartedProcess.notifyTextAvailable("Connecting to XSLT runner on " + endpoint + "\n", ProcessOutputTypes.SYSTEM);

    int tries = 0;
    IOException ex;
    do {
        final int d = (int)(System.currentTimeMillis() - s);
        try {
            @SuppressWarnings({"SocketOpenedButNotSafelyClosed"})
            final Socket socket = new Socket();
            socket.connect(endpoint, Math.max(CONNECT_TIMEOUT - d, 100));

            myStartedProcess.notifyTextAvailable("Connected to XSLT runner." + "\n", ProcessOutputTypes.SYSTEM);
            return socket.getInputStream();
        } catch (ConnectException e) {
            ex = e;
            try { Thread.sleep(500); } catch (InterruptedException ignored) { break; }
        }
        if (myStartedProcess.isProcessTerminated() || myStartedProcess.isProcessTerminating()) {
            return null;
        }
    } while (tries++ < 10);

    throw ex;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:OutputTabAdapter.java


示例19: bind

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
public boolean bind(int port) {
  if (port == BuiltInServerManager.getInstance().getPort()) {
    return true;
  }

  try {
    openChannels.add(bootstrap.bind(user.isAvailableExternally() ? new InetSocketAddress(port) : new InetSocketAddress(NetUtils.getLoopbackAddress(), port)));
    return true;
  }
  catch (Exception e) {
    NettyUtil.log(e, BuiltInServer.LOG);
    user.cannotBind(e, port);
    return false;
  }
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:16,代码来源:SubServer.java


示例20: getFreePorts

import com.intellij.util.net.NetUtils; //导入依赖的package包/类
public int[] getFreePorts() throws ExecutionException
{
	if(myFreePorts == null)
	{
		try
		{
			myFreePorts = NetUtils.findAvailableSocketPorts(2);
		}
		catch(IOException e)
		{
			throw new ExecutionException("Unable to find free ports", e);
		}
	}
	return myFreePorts;
}
 
开发者ID:consulo,项目名称:consulo-javaee,代码行数:16,代码来源:TomcatLocalModel.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Property类代码示例发布时间:2022-05-21
下一篇:
Java ConfigurationListener类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap