コード例 #1
0
ファイル: ServerConnection.java プロジェクト: bcorrigan/Goat
  private void connect() throws UnknownHostException, IOException {
    IrcServer = new Socket(serverName, 6667);

    BufferedReader br =
        new BufferedReader(
            new InputStreamReader(IrcServer.getInputStream(), BotStats.getInstance().getCharset()));
    PrintWriter pw =
        new PrintWriter(
            new OutputStreamWriter(
                IrcServer.getOutputStream(), BotStats.getInstance().getCharset()),
            true);
    ih = new InputHandler(br);
    oh = new OutputHandler(pw);

    ih.start();
    oh.start();

    new Message("", "NICK", BotStats.getInstance().getBotname(), "").send();
    new Message(
            "", "USER", "goat" + " nowhere.com " + serverName, BotStats.getInstance().getVersion())
        .send();
    // we sleep until we are connected, don't want to send these next messages too soon
    while (!connected) {
      try {
        sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }

    joinChannels();
  }
コード例 #2
0
ファイル: MynaInstaller.java プロジェクト: markporter/myna
  public static boolean exec(String cmd) throws Exception {
    int exitVal = -1;
    try {
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec(new String[] {"/bin/bash", "-c", cmd});

      OutputHandler err = new OutputHandler(proc.getErrorStream(), cmd);
      err.start();

      OutputHandler out = new OutputHandler(proc.getInputStream(), cmd);
      out.start();

      exitVal = proc.waitFor();

    } catch (Throwable t) {
      t.printStackTrace();
    }
    return (exitVal == 0);
  }