Package org.apache.tools.ant.taskdefs

# Class Redirector

java.lang.Object
org.apache.tools.ant.taskdefs.Redirector

    public class Redirector
    extends java.lang.Object

The Redirector class manages the setup and connection of input and output redirection for an Ant project component.

Since:
  Ant 1.6

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `Redirector​(ProjectComponent managingTask)` | Create a redirector instance for the given task
  `Redirector​(Task managingTask)` | Create a redirector instance for the given task

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `void` | `complete()` | Complete redirection.
  `ExecuteStreamHandler` | `createHandler()` | Create the StreamHandler to use with our Execute instance.
  `void` | `createStreams()` | Create the input, error and output streams based on the configuration options.
  `java.io.OutputStream` | `getErrorStream()` | Get the error stream for the redirector
  `java.io.InputStream` | `getInputStream()` | Get the input stream for the redirector
  `java.io.OutputStream` | `getOutputStream()` | Get the output stream for the redirector
  `protected void` | `handleErrorFlush​(java.lang.String output)` | Handle a flush operation on the error stream
  `protected void` | `handleErrorOutput​(java.lang.String output)` | Process error output
  `protected void` | `handleFlush​(java.lang.String output)` | Process data due to a flush operation.
  `protected int` | `handleInput​(byte[] buffer, int offset, int length)` | Handle an input request
  `protected void` | `handleOutput​(java.lang.String output)` | Pass output sent to System.out to specified output.
  `void` | `setAlwaysLog​(boolean alwaysLog)` | If true, (error and non-error) output will be "teed", redirected as specified while being sent to Ant's logging mechanism as if no redirection had taken place.
  `void` | `setAppend​(boolean append)` | Whether output should be appended to or overwrite an existing file.
  `void` | `setAppendProperties​(boolean appendProperties)` | This `Redirector`'s subordinate `PropertyOutputStream`s will not set their respective properties `while (appendProperties && append)`.
  `void` | `setBinaryOutput​(boolean b)` | Whether to consider the output created by the process binary.
  `void` | `setCreateEmptyFiles​(boolean createEmptyFiles)` | Whether output and error files should be created even when empty.
  `void` | `setError​(java.io.File error)` | Set the file to which standard error is to be redirected.
  `void` | `setError​(java.io.File[] error)` | Set the files to which standard error is to be redirected.
  `void` | `setErrorEncoding​(java.lang.String errorEncoding)` | Set the error encoding.
  `void` | `setErrorFilterChains​(java.util.Vector<FilterChain> errorFilterChains)` | Set the error `FilterChain`s.
  `void` | `setErrorProperty​(java.lang.String errorProperty)` | Property name whose value should be set to the error of the process.
  `void` | `setInput​(java.io.File input)` | Set the input to use for the task
  `void` | `setInput​(java.io.File[] input)` | Set the input to use for the task
  `void` | `setInputEncoding​(java.lang.String inputEncoding)` | Set the input encoding.
  `void` | `setInputFilterChains​(java.util.Vector<FilterChain> inputFilterChains)` | Set the input `FilterChain`s.
  `void` | `setInputString​(java.lang.String inputString)` | Set the string to use as input
  `void` | `setLogError​(boolean logError)` | Controls whether error output of exec is logged.
  `void` | `setLogInputString​(boolean logInputString)` | Set whether to include the value of the input string in log messages.
  `void` | `setOutput​(java.io.File out)` | File the output of the process is redirected to.
  `void` | `setOutput​(java.io.File[] out)` | Files the output of the process is redirected to.
  `void` | `setOutputEncoding​(java.lang.String outputEncoding)` | Set the output encoding.
  `void` | `setOutputFilterChains​(java.util.Vector<FilterChain> outputFilterChains)` | Set the output `FilterChain`s.
  `void` | `setOutputProperty​(java.lang.String outputProperty)` | Property name whose value should be set to the output of the process.
  `void` | `setProperties()` | Notify the `Redirector` that it is now okay to set any output and/or error properties.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Redirector

    public Redirector​(Task managingTask)
    Create a redirector instance for the given task
    Parameters:
      `managingTask` - the task for which the redirector is to work

  - ### Redirector

    public Redirector​(ProjectComponent managingTask)
    Create a redirector instance for the given task
    Parameters:
      `managingTask` - the project component for which the redirector is to work
    Since:
      Ant 1.6.3

- ## Method Details

  - ### setInput

    public void setInput​(java.io.File input)
    Set the input to use for the task
    Parameters:
      `input` - the file from which input is read.

  - ### setInput

    public void setInput​(java.io.File[] input)
    Set the input to use for the task
    Parameters:
      `input` - the files from which input is read.

  - ### setInputString

    public void setInputString​(java.lang.String inputString)
    Set the string to use as input
    Parameters:
      `inputString` - the string which is used as the input source

  - ### setLogInputString

    public void setLogInputString​(boolean logInputString)
    Set whether to include the value of the input string in log messages. Defaults to true.
    Parameters:
      `logInputString` - true or false.
    Since:
      Ant 1.7

  - ### setOutput

    public void setOutput​(java.io.File out)
    File the output of the process is redirected to. If error is not redirected, it too will appear in the output
    Parameters:
      `out` - the file to which output stream is written

  - ### setOutput

    public void setOutput​(java.io.File[] out)
    Files the output of the process is redirected to. If error is not redirected, it too will appear in the output
    Parameters:
      `out` - the files to which output stream is written

  - ### setOutputEncoding

    public void setOutputEncoding​(java.lang.String outputEncoding)
    Set the output encoding.
    Parameters:
      `outputEncoding` - `String`.

  - ### setErrorEncoding

    public void setErrorEncoding​(java.lang.String errorEncoding)
    Set the error encoding.
    Parameters:
      `errorEncoding` - `String`.

  - ### setInputEncoding

    public void setInputEncoding​(java.lang.String inputEncoding)
    Set the input encoding.
    Parameters:
      `inputEncoding` - `String`.

  - ### setLogError

    public void setLogError​(boolean logError)
    Controls whether error output of exec is logged. This is only useful when output is being redirected and error output is desired in the Ant log
    Parameters:
      `logError` - if true the standard error is sent to the Ant log system and not sent to output.

  - ### setAppendProperties

    public void setAppendProperties​(boolean appendProperties)
    This `Redirector`'s subordinate `PropertyOutputStream`s will not set their respective properties `while (appendProperties && append)`.
    Parameters:
      `appendProperties` - whether to append properties.

  - ### setError

    public void setError​(java.io.File error)
    Set the file to which standard error is to be redirected.
    Parameters:
      `error` - the file to which error is to be written

  - ### setError

    public void setError​(java.io.File[] error)
    Set the files to which standard error is to be redirected.
    Parameters:
      `error` - the file to which error is to be written

  - ### setOutputProperty

    public void setOutputProperty​(java.lang.String outputProperty)
    Property name whose value should be set to the output of the process.
    Parameters:
      `outputProperty` - the name of the property to be set with the task's output.

  - ### setAppend

    public void setAppend​(boolean append)
    Whether output should be appended to or overwrite an existing file. Defaults to false.
    Parameters:
      `append` - if true output and error streams are appended to their respective files, if specified.

  - ### setAlwaysLog

    public void setAlwaysLog​(boolean alwaysLog)
    If true, (error and non-error) output will be "teed", redirected as specified while being sent to Ant's logging mechanism as if no redirection had taken place. Defaults to false.
    Parameters:
      `alwaysLog` - `boolean`
    Since:
      Ant 1.6.3

  - ### setCreateEmptyFiles

    public void setCreateEmptyFiles​(boolean createEmptyFiles)
    Whether output and error files should be created even when empty. Defaults to true.
    Parameters:
      `createEmptyFiles` - `boolean`.

  - ### setErrorProperty

    public void setErrorProperty​(java.lang.String errorProperty)
    Property name whose value should be set to the error of the process.
    Parameters:
      `errorProperty` - the name of the property to be set with the error output.

  - ### setInputFilterChains

    public void setInputFilterChains​(java.util.Vector<FilterChain> inputFilterChains)
    Set the input `FilterChain`s.
    Parameters:
      `inputFilterChains` - `Vector` containing `FilterChain`.

  - ### setOutputFilterChains

    public void setOutputFilterChains​(java.util.Vector<FilterChain> outputFilterChains)
    Set the output `FilterChain`s.
    Parameters:
      `outputFilterChains` - `Vector` containing `FilterChain`.

  - ### setErrorFilterChains

    public void setErrorFilterChains​(java.util.Vector<FilterChain> errorFilterChains)
    Set the error `FilterChain`s.
    Parameters:
      `errorFilterChains` - `Vector` containing `FilterChain`.

  - ### setBinaryOutput

    public void setBinaryOutput​(boolean b)
    Whether to consider the output created by the process binary.

    Binary output will not be split into lines which may make error and normal output look mixed up when they get written to the same stream.

    Parameters:
      `b` - boolean
    Since:
      1.9.4

  - ### createStreams

    public void createStreams()
    Create the input, error and output streams based on the configuration options.

  - ### createHandler

    public ExecuteStreamHandler createHandler() throws BuildException
    Create the StreamHandler to use with our Execute instance.
    Returns:
      the execute stream handler to manage the input, output and error streams.
    Throws:
      `BuildException` - if the execute stream handler cannot be created.

  - ### handleOutput

    protected void handleOutput​(java.lang.String output)
    Pass output sent to System.out to specified output.
    Parameters:
      `output` - the data to be output

  - ### handleInput

    protected int handleInput​(byte[] buffer, int offset, int length) throws java.io.IOException
    Handle an input request
    Parameters:
      `buffer` - the buffer into which data is to be read.
      `offset` - the offset into the buffer at which data is stored.
      `length` - the amount of data to read
    Returns:
      the number of bytes read
    Throws:
      `java.io.IOException` - if the data cannot be read

  - ### handleFlush

    protected void handleFlush​(java.lang.String output)
    Process data due to a flush operation.
    Parameters:
      `output` - the data being flushed.

  - ### handleErrorOutput

    protected void handleErrorOutput​(java.lang.String output)
    Process error output
    Parameters:
      `output` - the error output data.

  - ### handleErrorFlush

    protected void handleErrorFlush​(java.lang.String output)
    Handle a flush operation on the error stream
    Parameters:
      `output` - the error information being flushed.

  - ### getOutputStream

    public java.io.OutputStream getOutputStream()
    Get the output stream for the redirector
    Returns:
      the redirector's output stream or null if no output has been configured

  - ### getErrorStream

    public java.io.OutputStream getErrorStream()
    Get the error stream for the redirector
    Returns:
      the redirector's error stream or null if no output has been configured

  - ### getInputStream

    public java.io.InputStream getInputStream()
    Get the input stream for the redirector
    Returns:
      the redirector's input stream or null if no output has been configured

  - ### complete

    public void complete() throws java.io.IOException
    Complete redirection. This operation will close any streams and create any specified property values.
    Throws:
      `java.io.IOException` - if the output properties cannot be read from their output streams.

  - ### setProperties

    public void setProperties()
    Notify the `Redirector` that it is now okay to set any output and/or error properties.