Example usage for org.eclipse.jgit.util.io MessageWriter MessageWriter

List of usage examples for org.eclipse.jgit.util.io MessageWriter MessageWriter

Introduction

In this page you can find the example usage for org.eclipse.jgit.util.io MessageWriter MessageWriter.

Prototype

public MessageWriter() 

Source Link

Document

Create an empty writer.

Usage

From source file:org.eclipse.egit.core.op.ConfigureGerritAfterCloneTask.java

License:Open Source License

private String runSshCommand(URIish sshUri, CredentialsProvider provider, FS fs, String command)
        throws IOException {
    RemoteSession session = null;// ww w .j  ava 2s .co m
    Process process = null;
    StreamCopyThread errorThread = null;
    try (MessageWriter stderr = new MessageWriter()) {
        session = SshSessionFactory.getInstance().getSession(sshUri, provider, fs, 1000 * timeout);
        process = session.exec(command, 0);
        errorThread = new StreamCopyThread(process.getErrorStream(), stderr.getRawStream());
        errorThread.start();
        try (BufferedReader reader = new BufferedReader(
                new InputStreamReader(process.getInputStream(), Constants.CHARSET))) {
            return reader.readLine();
        }
    } finally {
        if (errorThread != null) {
            try {
                errorThread.halt();
            } catch (InterruptedException e) {
                // Stop waiting and return anyway.
            } finally {
                errorThread = null;
            }
        }
        if (process != null) {
            process.destroy();
        }
        if (session != null) {
            SshSessionFactory.getInstance().releaseSession(session);
        }
    }
}