- reduced visibility

This commit is contained in:
Sebastian Stenzel
2014-12-16 17:18:20 +01:00
parent b7f3f00ce2
commit 6b45d62aa1
3 changed files with 19 additions and 6 deletions
@@ -20,16 +20,22 @@ import org.cryptomator.ui.util.mount.CommandFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CommandResult {
public final class CommandResult {
private static final Logger LOG = LoggerFactory.getLogger(CommandResult.class);
private final Process process;
public CommandResult(Process process) {
/**
* @param process An <strong>already finished</strong> process.
*/
CommandResult(Process process) {
this.process = process;
}
/**
* @return Data written to STDOUT
*/
public String getOutput() throws CommandFailedException {
try (InputStream in = process.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
copy(in, out);
@@ -39,6 +45,9 @@ public class CommandResult {
}
}
/**
* @return Data written to STDERR
*/
public String getError() throws CommandFailedException {
try (InputStream in = process.getErrorStream(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {
copy(in, out);
@@ -48,11 +57,14 @@ public class CommandResult {
}
}
/**
* @return Exit value of the process
*/
public int getExitValue() throws CommandFailedException {
return process.exitValue();
}
public void logDebugInfo() {
void logDebugInfo() {
if (LOG.isDebugEnabled()) {
try {
LOG.debug("Command execution finished. Exit code: {}\n" + "Output:\n" + "{}\n" + "Error:\n" + "{}\n", process.exitValue(), getOutput(), getError());
@@ -5,6 +5,7 @@
*
* Contributors:
* Markus Kreusch
* Sebastian Stenzel - Refactoring
******************************************************************************/
package org.cryptomator.ui.util.command;
@@ -19,7 +19,7 @@ import java.util.concurrent.locks.ReentrantLock;
import org.cryptomator.ui.util.mount.CommandFailedException;
class FutureCommandResult implements Future<CommandResult>, Runnable {
final class FutureCommandResult implements Future<CommandResult>, Runnable {
private final Process process;
private final AtomicBoolean canceled = new AtomicBoolean();
@@ -29,7 +29,7 @@ class FutureCommandResult implements Future<CommandResult>, Runnable {
private CommandFailedException exception;
public FutureCommandResult(Process process) {
FutureCommandResult(Process process) {
this.process = process;
}