Package org.apache.tools.ant.taskdefs
Class Redirector
java.lang.Object
org.apache.tools.ant.taskdefs.Redirector
The Redirector class manages the setup and connection of input and output
redirection for an Ant project component.
- Since:
- Ant 1.6
-
Constructor Summary
ConstructorDescriptionRedirector
(ProjectComponent managingTask) Create a redirector instance for the given taskRedirector
(Task managingTask) Create a redirector instance for the given task -
Method Summary
Modifier and TypeMethodDescriptionvoid
complete()
Complete redirection.Create the StreamHandler to use with our Execute instance.void
Create the input, error and output streams based on the configuration options.Get the error stream for the redirectorGet the input stream for the redirectorGet the output stream for the redirectorprotected void
handleErrorFlush
(String output) Handle a flush operation on the error streamprotected void
handleErrorOutput
(String output) Process error outputprotected void
handleFlush
(String output) Process data due to a flush operation.protected int
handleInput
(byte[] buffer, int offset, int length) Handle an input requestprotected 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) ThisRedirector
's subordinatePropertyOutputStream
s will not set their respective propertieswhile (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
setDiscardError
(boolean discard) Whether error output should be discarded.void
setDiscardOutput
(boolean discard) Whether output should be discarded.void
Set the file to which standard error is to be redirected.void
Set the files to which standard error is to be redirected.void
setErrorEncoding
(String errorEncoding) Set the error encoding.void
setErrorFilterChains
(Vector<FilterChain> errorFilterChains) Set the errorFilterChain
s.void
setErrorProperty
(String errorProperty) Property name whose value should be set to the error of the process.void
Set the input to use for the taskvoid
Set the input to use for the taskvoid
setInputEncoding
(String inputEncoding) Set the input encoding.void
setInputFilterChains
(Vector<FilterChain> inputFilterChains) Set the inputFilterChain
s.void
setInputString
(String inputString) Set the string to use as inputvoid
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
File the output of the process is redirected to.void
Files the output of the process is redirected to.void
setOutputEncoding
(String outputEncoding) Set the output encoding.void
setOutputFilterChains
(Vector<FilterChain> outputFilterChains) Set the outputFilterChain
s.void
setOutputProperty
(String outputProperty) Property name whose value should be set to the output of the process.void
Notify theRedirector
that it is now okay to set any output and/or error properties.
-
Constructor Details
-
Redirector
Create a redirector instance for the given task- Parameters:
managingTask
- the task for which the redirector is to work
-
Redirector
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
Set the input to use for the task- Parameters:
input
- the file from which input is read.
-
setInput
Set the input to use for the task- Parameters:
input
- the files from which input is read.
-
setInputString
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
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
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
Set the output encoding.- Parameters:
outputEncoding
-String
.
-
setErrorEncoding
Set the error encoding.- Parameters:
errorEncoding
-String
.
-
setInputEncoding
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) ThisRedirector
's subordinatePropertyOutputStream
s will not set their respective propertieswhile (appendProperties && append)
.- Parameters:
appendProperties
- whether to append properties.
-
setError
Set the file to which standard error is to be redirected.- Parameters:
error
- the file to which error is to be written
-
setError
Set the files to which standard error is to be redirected.- Parameters:
error
- the file to which error is to be written
-
setOutputProperty
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.
-
setDiscardOutput
public void setDiscardOutput(boolean discard) Whether output should be discarded.Defaults to false.
- Parameters:
discard
- if true output streams are discarded.- Since:
- Ant 1.10.10
- See Also:
-
setDiscardError
public void setDiscardError(boolean discard) Whether error output should be discarded.Defaults to false.
- Parameters:
discard
- if true error streams are discarded.- Since:
- Ant 1.10.10
- See Also:
-
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
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
Set the inputFilterChain
s.- Parameters:
inputFilterChains
-Vector
containingFilterChain
.
-
setOutputFilterChains
Set the outputFilterChain
s.- Parameters:
outputFilterChains
-Vector
containingFilterChain
.
-
setErrorFilterChains
Set the errorFilterChain
s.- Parameters:
errorFilterChains
-Vector
containingFilterChain
.
-
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
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
Pass output sent to System.out to specified output.- Parameters:
output
- the data to be output
-
handleInput
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
-
handleFlush
Process data due to a flush operation.- Parameters:
output
- the data being flushed.
-
handleErrorOutput
Process error output- Parameters:
output
- the error output data.
-
handleErrorFlush
Handle a flush operation on the error stream- Parameters:
output
- the error information being flushed.
-
getOutputStream
Get the output stream for the redirector- Returns:
- the redirector's output stream or null if no output has been configured
-
getErrorStream
Get the error stream for the redirector- Returns:
- the redirector's error stream or null if no output has been configured
-
getInputStream
Get the input stream for the redirector- Returns:
- the redirector's input stream or null if no output has been configured
-
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.
-
setProperties
public void setProperties()Notify theRedirector
that it is now okay to set any output and/or error properties.
-