org.apache.tools.ant.taskdefs

Class Redirector

public class Redirector extends 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(Task managingTask)
Create a redirector instance for the given task
Redirector(ProjectComponent managingTask)
Create a redirector instance for the given task
Method Summary
voidcomplete()
Complete redirection.
ExecuteStreamHandlercreateHandler()
Create the StreamHandler to use with our Execute instance.
voidcreateStreams()
Create the input, error and output streams based on the configuration options.
OutputStreamgetErrorStream()
Get the error stream for the redirector
InputStreamgetInputStream()
Get the input stream for the redirector
OutputStreamgetOutputStream()
Get the output stream for the redirector
protected voidhandleErrorFlush(String output)
Handle a flush operation on the error stream
protected voidhandleErrorOutput(String output)
Process error output
protected voidhandleFlush(String output)
Process data due to a flush operation.
protected inthandleInput(byte[] buffer, int offset, int length)
Handle an input request
protected voidhandleOutput(String output)
Pass output sent to System.out to specified output.
voidsetAlwaysLog(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.
voidsetAppend(boolean append)
Whether output should be appended to or overwrite an existing file.
voidsetAppendProperties(boolean appendProperties)
This Redirector's subordinate PropertyOutputStreams will not set their respective properties while (appendProperties && append).
voidsetCreateEmptyFiles(boolean createEmptyFiles)
Whether output and error files should be created even when empty.
voidsetError(File error)
Set the file to which standard error is to be redirected.
voidsetError(File[] error)
Set the files to which standard error is to be redirected.
voidsetErrorEncoding(String errorEncoding)
Set the error encoding.
voidsetErrorFilterChains(Vector errorFilterChains)
Set the error FilterChains.
voidsetErrorProperty(String errorProperty)
Property name whose value should be set to the error of the process.
voidsetInput(File input)
Set the input to use for the task
voidsetInput(File[] input)
Set the input to use for the task
voidsetInputEncoding(String inputEncoding)
Set the input encoding.
voidsetInputFilterChains(Vector inputFilterChains)
Set the input FilterChains.
voidsetInputString(String inputString)
Set the string to use as input
voidsetLogError(boolean logError)
Controls whether error output of exec is logged.
voidsetOutput(File out)
File the output of the process is redirected to.
voidsetOutput(File[] out)
Files the output of the process is redirected to.
voidsetOutputEncoding(String outputEncoding)
Set the output encoding.
voidsetOutputFilterChains(Vector outputFilterChains)
Set the output FilterChains.
voidsetOutputProperty(String outputProperty)
Property name whose value should be set to the output of the process.
voidsetProperties()
Notify the Redirector that it is now okay to set any output and/or error properties.

Constructor Detail

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 Detail

complete

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

Throws: IOException if the output properties cannot be read from their output streams.

createHandler

public ExecuteStreamHandler createHandler()
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)
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: IOException if the data cannot be 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