<commit_before>/*
 * $Id$
 */
package lia.util.net.common;

import ch.ethz.ssh2.StreamGobbler;
import com.sshtools.common.configuration.SshToolsConnectionProfile;
import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
import com.sshtools.j2ssh.session.SessionChannelClient;
import org.ietf.jgss.GSSException;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author <NAME>
 */
public class GSISSHControlStream implements ControlStream {

    // configuration parameters
    private final String hostname;
    private final String username;
    private final int port;

    /**
     * the SSH connection & session
     */
    private SshClient conn;
    private SessionChannelClient sess;
    private String cmd;
    private String customShell;

    /**
     * Creates a new GSI SSH control connection on the default ssh port.
     * <p>
     * Same as {@link #GSISSHControlStream(String, String, int) GSISSHControlStream(hostname, username, 22)}
     *
     * @param hostname: remote host
     * @param username: remote account
     * @throws IOException in case of failure
     */
    public GSISSHControlStream(String hostname, String username) {
        this(hostname, username, 22);
    }

    /**
     * Creates a new SSH control connection on the specified remote GSI sshd server port
     *
     * @param port:     remote GSI-sshd port
     * @param hostname: remote host
     * @param username: remote account
     * @throws IOException in case of failure
     */
    public GSISSHControlStream(String hostname, String username, int port) {
        this.hostname = hostname;
        this.username = username;
        this.port = port;
    }

    // TEST
    public static void main(String[] args) throws IOException {
        ControlStream cs = new GSISSHControlStream(args[0], args[1]);
        cs.startProgram(args[2]);

		/* read stdout */
        InputStream stdout = new StreamGobbler(cs.getProgramStdOut());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        System.out.println("ExitCode:" + cs.getExitCode());
        cs.close();
    }

    public void connect() throws IOException {
        lia.gsi.ssh.GSIAuthenticationClient gsiAuth = null;
        try {
            gsiAuth = new lia.gsi.ssh.GSIAuthenticationClient();
            gsiAuth.setUsername(username);
        } catch (GSSException e) {
            throw new IOException("Cannot load grid credentials.");
        }
        conn = new SshClient();<commit_msg>adjusting number of arguments<commit_after>/*
 * $Id$
 */
package lia.util.net.common;

import ch.ethz.ssh2.StreamGobbler;
import com.sshtools.common.configuration.SshToolsConnectionProfile;
import com.sshtools.j2ssh.SshClient;
import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
import com.sshtools.j2ssh.session.SessionChannelClient;
import org.ietf.jgss.GSSException;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author <NAME>
 */
public class GSISSHControlStream implements ControlStream {

    // configuration parameters
    private final String hostname;
    private final String username;
    private final int port;

    /**
     * the SSH connection & session
     */
    private SshClient conn;
    private SessionChannelClient sess;
    private String cmd;
    private String customShell;

    /**
     * Creates a new GSI SSH control connection on the default ssh port.
     * <p>
     * Same as {@link #GSISSHControlStream(String, String, int) GSISSHControlStream(hostname, username, 22)}
     *
     * @param hostname: remote host
     * @param username: remote account
     * @throws IOException in case of failure
     */
    public GSISSHControlStream(String hostname, String username) {
        this(hostname, username, 22);
    }

    /**
     * Creates a new SSH control connection on the specified remote GSI sshd server port
     *
     * @param port:     remote GSI-sshd port
     * @param hostname: remote host
     * @param username: remote account
     * @throws IOException in case of failure
     */
    public GSISSHControlStream(String hostname, String username, int port) {
        this.hostname = hostname;
        this.username = username;
        this.port = port;
    }

    // TEST
    public static void main(String[] args) throws IOException {
        ControlStream cs = new GSISSHControlStream(args[0], args[1]);
        cs.startProgram(args[3]);

		/* read stdout */
        InputStream stdout = new StreamGobbler(cs.getProgramStdOut());
        BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
        while (true) {
            String line = br.readLine();
            if (line == null)
                break;
            System.out.println(line);
        }
        System.out.println("ExitCode:" + cs.getExitCode());
        cs.close();
    }

    public void connect() throws IOException {
        lia.gsi.ssh.GSIAuthenticationClient gsiAuth = null;
        try {
            gsiAuth = new lia.gsi.ssh.GSIAuthenticationClient();
            gsiAuth.setUsername(username);
        } catch (GSSException e) {
            throw new IOException("Cannot load grid credentials.");
        }
        conn = new SshClient();
{'fraction_non_alphanumeric': 0.09619604974396488, 'fraction_numerical': 0.004023408924652524, 'mean_word_length': 2.6853099730458223, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487849', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1514, 'n_words': 426}