All Packages  This Package  Class Hierarchy  Class Search  Index

Class app.authkit.tools.tasks.CommonTask
java.lang.Object
   |
   +----app.authkit.tools.tasks.CommonTask

  Summary

public abstract class  CommonTask
     extends java.lang.Object
     implements app.authkit.envoy.Task
{
          // Constructors 1
     protected CommonTask();

          // Methods 5
     protected int execute(String[], InputStream, OutputStream, OutputStream);
     protected void explain(String);
     protected void explain(Throwable);
     public boolean producesOutput();
     protected String[] substitute(String[], String, String);
}

CommonTask is a partial Task implementation used as a base-class. It defines a default implementation of producesOutput() that returns false. Only Tasks that produce output need to provide an override. No definition of perform() is provided, so all CommonTasks must define it.

CommonTask also provides utility methods useful to Tasks that execute external programs. Many Tasks are written to run other programs as root, so these simplify such Tasks.


  Cross Reference

Extended By:
AppBundleLockdownTask, RunEat





  Constructors

· CommonTask

Summary  |  Top
   protected CommonTask() 

Visible only to subclasses.



  Methods

· producesOutput

Summary  |  Top
   public boolean producesOutput() 

Does this Task produce output on System.out that should be collected and returned to the Envoy's master?

Returns false. Only subclasses that produce output need to override.

Implements:
producesOutput in interface Task


· explain

Summary  |  Top
   protected void explain(String text) 

Emit line of text on stderr, flushing stdout first.



· explain

Summary  |  Top
   protected void explain(Throwable toExplain) 

Emit stack trace on stderr, flushing stdout first.



· substitute

Summary  |  Top
   protected String[] substitute(String[] progArray, 
                                 String pattern, 
                                 String replacement) 

Replicate progArray, substituting each occurrence of pattern with replacement. The pattern must be a distinct String in progArray. It may appear multiple times. Sub-patterns within progArray Strings do not undergo pattern substitution.



· execute

Summary  |  Top
   protected int execute(String[] progArray, 
                         InputStream stdin, 
                         OutputStream stdout, 
                         OutputStream stderr) 

Treat the progArray as a command to execute with Runtime.exec(), feeding the Process's streams to the given streams using independent daemon threads running a glguerin.util.Streamer.

The Process's input-consuming stream is fed by the given InputStream, or is unfed if the stream is null. To cause the Process to see an immediate EOF, you should provide a non-null InputStream that will return an immediate EOF. For example, provide a ByteArrayInputStream wrapping a byte[0].

If an OutputStream is null, the Process's output destined for that stream is discarded. Otherwise the bytes are written to the provided OutputStream using a Streamer.

None of the streams provided are closed by the Streamer threads that move the data. All the Streamer threads are daemon Threads in the current ThreadGroup.

The Process's exit-status is returned, or -1 if can't exec() it, or -2 if can't waitFor() it. An unchecked exception may also be thrown.



All Packages  This Package  Class Hierarchy  Class Search  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.7