org.entityfs.support.io
Class AbstractCommands

java.lang.Object
  extended by org.entityfs.support.io.AbstractCommands

public abstract class AbstractCommands
extends Object

This is an abstract class that command class implementations can inherit. It contains methods for running external commands.

Since:
1.0
Author:
Karl Gustafsson
In_jar:
entityfs-core

Constructor Summary
protected AbstractCommands(LogAdapterHolder lah)
          Constructor.
 
Method Summary
protected  Process execAndWait(String cmd)
          Execute an external command, such as ls and wait for it to complete.
protected  String getErrorMessage(Process p, String cmd)
          Create an error message from the error message from a process.
protected  LogAdapter getLogAdapter()
          Get the file system's current log adapter.
protected  String getOutput(InputStream is)
          Get the output from a stream, for instance from the output of a process.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCommands

protected AbstractCommands(LogAdapterHolder lah)
Constructor.

Parameters:
lah - The file system's log adapter holder.
Method Detail

getLogAdapter

protected LogAdapter getLogAdapter()
Get the file system's current log adapter.

Returns:
The file system's current log adapter.

execAndWait

protected Process execAndWait(String cmd)
                       throws InterruptedException
Execute an external command, such as ls and wait for it to complete.

This does not work if the command generates a lot of output because the process' output buffers are limited in size. In that case the running process' output must be regularly read to keep it from stalling. See Process.

Parameters:
cmd - The command to run
Returns:
The Process object for the completed process.
Throws:
InterruptedException - If the command was interrupted.

getOutput

protected String getOutput(InputStream is)
Get the output from a stream, for instance from the output of a process.

Parameters:
is - The stream to read from. The stream is closed by this method.
Returns:
The output contained in the stream.

getErrorMessage

protected String getErrorMessage(Process p,
                                 String cmd)
Create an error message from the error message from a process. Call this to get an error message if the process exited with an exit code other than 0.

Parameters:
p - The process that generated an error.
cmd - The command that failed.
Returns:
An error message.