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


Java IOUtils类代码示例

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


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

示例1: executeCommand

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public String executeCommand(ShellCommand aCommand) throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("localhost", 2222);
    try {
        ssh.authPublickey("root");
        try (Session session = ssh.startSession()) {
            Session.Command command = session.exec(aCommand.getCommand());
            String text = IOUtils.readFully(command.getInputStream()).toString();
            command.join(5, TimeUnit.SECONDS);
            return text;
        }
    } finally {
        ssh.disconnect();
    }
}
 
开发者ID:evsinev,项目名称:docker-network-veth,代码行数:18,代码来源:CommandServiceSsh.java

示例2: connectfromPItoServer

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
public static void connectfromPItoServer(int fotosAnzahl, int belichtungsDauer)
            throws IOException {
    	final String ipServer = Inet4Address.getLocalHost().getHostAddress();
//    	System.out.println(Inet4Address.getAllByName("raspberrypi"));
//    	System.out.println(fotosAnzahl);
        final SSHClient ssh = new SSHClient();
        ssh.addHostKeyVerifier(new NullHostKeyVerifier());
//        for(int i = 0; i < InetAddress.)
//        ssh.connect("192.168.2.100", 22);
        ssh.connect(Settings.raspberryIP, 22);
       
        try {
         ssh.authPassword("pi", "raspberry");
            final Session session = ssh.startSession();
            try {
            	System.out.println("BEGINNE MIt tray");
                final Command cmd = session.exec("java -jar Desktop/Driver/Java/client.jar " + fotosAnzahl + " " + ipServer + " " + belichtungsDauer);
                System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
                cmd.join(5, TimeUnit.SECONDS);
                System.out.println("\n** exit status: " + cmd.getExitStatus());
            } finally {
                session.close();
            }
        } finally {
            ssh.disconnect();
            ssh.close();
        }
    }
 
开发者ID:Raldir,项目名称:3DScanner.RaspberryPi,代码行数:29,代码来源:Exec.java

示例3: connect_to_virtual_box

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Test
public void connect_to_virtual_box() throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("localhost", 2222);
    try {
        ssh.authPublickey("root");
        try (Session session = ssh.startSession()) {
            Session.Command command = session.exec("ls -l");
            System.out.println(IOUtils.readFully(command.getInputStream()).toString());
            command.join(5, TimeUnit.SECONDS);
        }
    } finally {
        ssh.disconnect();
    }

}
 
开发者ID:evsinev,项目名称:docker-network-veth,代码行数:18,代码来源:SshClientTest.java

示例4: prepareUpload

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
private void prepareUpload(Session session, String command) {
    try (Session.Command sshCommand = session.exec(command)) {
        sshCommand.join();
        if (sshCommand.getExitStatus() != 0) {
            throw new ArtifactExecutionException("Command " + command + " failed with exit status " + sshCommand.getExitStatus());
        } else {
            log.info("Prepare upload finished normally with standard output [{}] and error output [{}]",
                    command,
                    new String(IOUtils.readFully(sshCommand.getInputStream()).toByteArray()),
                    new String(IOUtils.readFully(sshCommand.getErrorStream()).toByteArray()));
        }
    } catch (IOException e) {
        if (ExceptionUtils.indexOfType(e, InterruptedException.class) >= 0) {
            throw new ArtifactInterruptedException("Execution has been interrupted", e);
        } else {
            throw new ArtifactExecutionException("Command " + command + " has failed", e);
        }
    }
}
 
开发者ID:vuminhkh,项目名称:tosca-runtime,代码行数:20,代码来源:SSHJExecutor.java

示例5: executeSshCommand

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
private Pair<Integer, String> executeSshCommand(SSHClient ssh, String command) throws IOException {
    Session session = null;
    Command cmd = null;
    try {
        session = startSshSession(ssh);
        cmd = session.exec(command);
        String stdout = IOUtils.readFully(cmd.getInputStream()).toString();
        cmd.join(10, TimeUnit.SECONDS);
        return Pair.of(cmd.getExitStatus(), stdout);
    } finally {
        if (cmd != null) {
            cmd.close();
        }
        if (session != null) {
            session.close();
        }
    }
}
 
开发者ID:hortonworks,项目名称:cloudbreak,代码行数:19,代码来源:CountRecipeResultsTest.java

示例6: run

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public String run() throws RaspiQueryException {
    LOGGER.debug("Querying firmware version, vcgencmd path={}", this.vcgencmdPath);
    try {
        Session session = getSSHClient().startSession();
        String cmdString = vcgencmdPath + " version";
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        String output = IOUtils.readFully(cmd.getInputStream())
                .toString();
        final String result = this.parseFirmwareVersion(output);
        LOGGER.debug("Firmware version: {}", result);
        return result;
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:18,代码来源:FirmwareQuery.java

示例7: run

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public Double run() throws RaspiQueryException {
    LOGGER.info("Querying load average for time period {}", this.period);
    Session session;
    try {
        session = getSSHClient().startSession();
        session.allocateDefaultPTY();
        final Command cmd = session.exec(LOAD_AVG_CMD);
        cmd.join(30, TimeUnit.SECONDS);
        cmd.close();
        final String output = IOUtils.readFully(cmd.getInputStream())
                .toString();
        return this.parseLoadAverage(output, this.period);
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:18,代码来源:LoadAverageQuery.java

示例8: run

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public String run() throws RaspiQueryException {
    LOGGER.debug("Querying system time via 'date --rfc-2822'.");
    try {
        Session session = getSSHClient().startSession();
        String cmdString = "date --rfc-2822";
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        String output = IOUtils.readFully(cmd.getInputStream())
                .toString();
        final String result = output.trim();
        LOGGER.debug("System time: {}", result);
        return result;
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:18,代码来源:SystemtimeQuery.java

示例9: queryWirelessInterfaceWithProcNetWireless

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
/**
 * Queries the link level and signal quality of the wireless interfaces via
 * "cat /proc/net/wireless".
 *
 * @param interfaceName name of the wireless interface
 * @throws RaspiQueryException if something goes wrong
 */
private WlanBean queryWirelessInterfaceWithProcNetWireless(String interfaceName)
        throws RaspiQueryException {
    LOGGER.info("Querying wireless interface {} from /proc/net/wireless ...", interfaceName);
    Session session;
    try {
        session = getSSHClient().startSession();
        final String cmdString = "cat /proc/net/wireless";
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        String output = IOUtils.readFully(cmd.getInputStream()).toString();
        LOGGER.debug("Real output of /proc/net/wireless: \n{}",
                output);
        return this.parseProcNetWireless(output, interfaceName);
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:25,代码来源:NetworkInformationQuery.java

示例10: queryWirelessInterfaceWithIwconfig

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
private WlanBean queryWirelessInterfaceWithIwconfig(String interfaceName, String iwconfigPath) throws RaspiQueryException {
    LOGGER.info("Executing {} to query wireless interface '{}'...", iwconfigPath, interfaceName);
    Session session;
    try {
        session = getSSHClient().startSession();
        session.allocateDefaultPTY();
        final String cmdString = "LC_ALL=C " + iwconfigPath + " " + interfaceName;
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        String output = IOUtils.readFully(cmd.getInputStream())
                .toString();
        LOGGER.debug("Output of '{}': \n{}", cmdString, output);
        return this.parseIwconfigOutput(output);
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:18,代码来源:NetworkInformationQuery.java

示例11: checkCarrier

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
/**
 * Checks if the specified interface has a carrier up and running via
 * "cat /sys/class/net/[interface]/carrier".
 *
 * @param interfaceName the interface to check
 * @return true, when the interface has a carrier up and running
 * @throws RaspiQueryException if something goes wrong
 */
private boolean checkCarrier(String interfaceName)
        throws RaspiQueryException {
    LOGGER.info("Checking carrier of {}...", interfaceName);
    Session session;
    try {
        session = getSSHClient().startSession();
        final String cmdString = "cat /sys/class/net/" + interfaceName + "/carrier";
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        final String output = IOUtils.readFully(cmd.getInputStream()).toString();
        if (output.contains("1")) {
            LOGGER.debug("{} has a carrier up and running.",
                    interfaceName);
            return true;
        } else {
            LOGGER.debug("{} has no carrier.", interfaceName);
            return false;
        }
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:31,代码来源:NetworkInformationQuery.java

示例12: queryInterfaceList

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
/**
 * Queries which interfaces are available via "/sys/class/net". Loopback
 * interfaces are excluded.
 *
 * @return a List with all interface names (eth0, wlan0,...).
 * @throws RaspiQueryException if something goes wrong
 */
private List<String> queryInterfaceList() throws RaspiQueryException {
    LOGGER.info("Querying network interfaces...");
    Session session;
    try {
        session = getSSHClient().startSession();
        final String cmdString = "ls -1 /sys/class/net";
        final Session.Command cmd = session.exec(cmdString);
        cmd.join(30, TimeUnit.SECONDS);
        final String output = IOUtils.readFully(
                cmd.getInputStream()).toString();
        final String[] lines = output.split("\n");
        final List<String> interfaces = new ArrayList<String>();
        for (String interfaceLine : lines) {
            if (!interfaceLine.startsWith("lo")) {
                LOGGER.debug("Found interface {}.", interfaceLine);
                interfaces.add(interfaceLine);
            }
        }
        return interfaces;
    } catch (IOException e) {
        throw RaspiQueryException.createTransportFailure(e);
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:31,代码来源:NetworkInformationQuery.java

示例13: queryCpuTemp

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
/**
 * Queries the current CPU temperature.
 *
 * @param vcgencmdPath the path to vcgencmd
 * @return the temperature in Celsius
 * @throws RaspiQueryException if something goes wrong
 */
private Double queryCpuTemp(String vcgencmdPath)
        throws RaspiQueryException {
    if (client != null) {
        if (client.isConnected() && client.isAuthenticated()) {
            Session session;
            try {
                session = client.startSession();
                final String cmdString = vcgencmdPath + " measure_temp";
                final Command cmd = session.exec(cmdString);
                cmd.join(30, TimeUnit.SECONDS);
                String output = IOUtils.readFully(cmd.getInputStream()).toString();
                return this.parseTemperature(output);
            } catch (IOException e) {
                throw RaspiQueryException.createTransportFailure(hostname,
                        e);
            }
        } else {
            throw new IllegalStateException("You must establish a connection first.");
        }
    } else {
        throw new IllegalStateException("You must establish a connection first.");
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:31,代码来源:RaspiQuery.java

示例14: queryDiskUsage

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public final List<DiskUsageBean> queryDiskUsage()
        throws RaspiQueryException {
    LOGGER.info("Querying disk usage...");
    if (client != null) {
        if (client.isConnected() && client.isAuthenticated()) {
            Session session;
            try {
                session = client.startSession();
                final Command cmd = session.exec(DISK_USAGE_CMD);
                cmd.join(30, TimeUnit.SECONDS);
                return this.parseDiskUsage(IOUtils
                        .readFully(cmd.getInputStream()).toString().trim());
            } catch (IOException e) {
                throw RaspiQueryException.createTransportFailure(hostname,
                        e);
            }
        } else {
            throw new IllegalStateException("You must establish a connection first.");
        }
    } else {
        throw new IllegalStateException("You must establish a connection first.");
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:25,代码来源:RaspiQuery.java

示例15: queryDistributionName

import net.schmizz.sshj.common.IOUtils; //导入依赖的package包/类
@Override
public final String queryDistributionName() throws RaspiQueryException {
    LOGGER.info("Querying distribution name...");
    if (client != null) {
        if (client.isConnected() && client.isAuthenticated()) {
            Session session;
            try {
                session = client.startSession();
                final Command cmd = session.exec(DISTRIBUTION_CMD);
                cmd.join(30, TimeUnit.SECONDS);
                return this.parseDistribution(IOUtils.readFully(cmd.getInputStream()).toString().trim());
            } catch (IOException e) {
                throw RaspiQueryException.createTransportFailure(hostname,
                        e);
            }
        } else {
            throw new IllegalStateException(
                    "You must establish a connection first.");
        }
    } else {
        throw new IllegalStateException(
                "You must establish a connection first.");
    }
}
 
开发者ID:eidottermihi,项目名称:rpicheck,代码行数:25,代码来源:RaspiQuery.java


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