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


Java NetUtils类代码示例

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


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


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