org.apache.tools.ant.taskdefs

Class 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

Redirector(ProjectComponent managingTask)
Create a redirector instance for the given task
Redirector(Task managingTask)
Create a redirector instance for the given task

Method Summary

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.
OutputStream
getErrorStream()
Get the error stream for the redirector
InputStream
getInputStream()
Get the input stream for the redirector
OutputStream
getOutputStream()
Get the output stream for the redirector
protected void
handleErrorFlush(String output)
Handle a flush operation on the error stream
protected void
handleErrorOutput(String output)
Process error output
protected void
handleFlush(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(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 PropertyOutputStreams will not set their respective properties while (appendProperties && append).
void
setCreateEmptyFiles(boolean createEmptyFiles)
Whether output and error files should be created even when empty.
void
setError(File error)
Set the file to which standard error is to be redirected.
void
setError(File[] error)
Set the files to which standard error is to be redirected.
void
setErrorEncoding(String errorEncoding)
Set the error encoding.
void
setErrorFilterChains(Vector errorFilterChains)
Set the error FilterChains.
void
setErrorProperty(String errorProperty)
Property name whose value should be set to the error of the process.
void
setInput(File input)
Set the input to use for the task
void
setInput(File[] input)
Set the input to use for the task
void
setInputEncoding(String inputEncoding)
Set the input encoding.
void
setInputFilterChains(Vector inputFilterChains)
Set the input FilterChains.
void
setInputString(String inputString)
Set the string to use as input
void
setLogError(boolean logError)
Controls whether error output of exec is logged.
void
setOutput(File out)
File the output of the process is redirected to.
void
setOutput(File[] out)
Files the output of the process is redirected to.
void
setOutputEncoding(String outputEncoding)
Set the output encoding.
void
setOutputFilterChains(Vector outputFilterChains)
Set the output FilterChains.
void
setOutputProperty(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.

Constructor Details

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

Redirector

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

Method Details

complete

public void complete()
            throws IOException
Complete redirection. This operation will close any streams and create any specified property values.

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.

createStreams

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

getErrorStream

public 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 InputStream getInputStream()
Get the input stream for the redirector
Returns:
the redirector's input stream or null if no output has been configured

getOutputStream

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

handleErrorFlush

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

handleErrorOutput

protected void handleErrorOutput(String output)
Process error output
Parameters:
output - the error output data.

handleFlush

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

handleInput

protected int handleInput(byte[] buffer,
                          int offset,
                          int length)
            throws 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

handleOutput

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

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

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.

setAppendProperties

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

setCreateEmptyFiles

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

setError

public void setError(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(File[] error)
Set the files to which standard error is to be redirected.
Parameters:
error - the file to which error is to be written

setErrorEncoding

public void setErrorEncoding(String errorEncoding)
Set the error encoding.
Parameters:
errorEncoding - String.

setErrorFilterChains

public void setErrorFilterChains(Vector errorFilterChains)
Set the error FilterChains.
Parameters:
errorFilterChains - Vector containing FilterChain.

setErrorProperty

public void setErrorProperty(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.

setInput

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

setInput

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

setInputEncoding

public void setInputEncoding(String inputEncoding)
Set the input encoding.
Parameters:
inputEncoding - String.

setInputFilterChains

public void setInputFilterChains(Vector inputFilterChains)
Set the input FilterChains.
Parameters:
inputFilterChains - Vector containing FilterChain.

setInputString

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

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.

setOutput

public void setOutput(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(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(String outputEncoding)
Set the output encoding.
Parameters:
outputEncoding - String.

setOutputFilterChains

public void setOutputFilterChains(Vector outputFilterChains)
Set the output FilterChains.
Parameters:
outputFilterChains - Vector containing FilterChain.

setOutputProperty

public void setOutputProperty(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.

setProperties

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

Copyright B) 2000-2007 Apache Software Foundation. All Rights Reserved.