Package org.apache.tools.ant.taskdefs
Class Redirector
- java.lang.Object
-
- org.apache.tools.ant.taskdefs.Redirector
-
public class Redirector extends java.lang.ObjectThe 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 taskRedirector(Task managingTask)Create a redirector instance for the given task
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.java.io.OutputStreamgetErrorStream()Get the error stream for the redirectorjava.io.InputStreamgetInputStream()Get the input stream for the redirectorjava.io.OutputStreamgetOutputStream()Get the output stream for the redirectorprotected voidhandleErrorFlush(java.lang.String output)Handle a flush operation on the error streamprotected voidhandleErrorOutput(java.lang.String output)Process error outputprotected voidhandleFlush(java.lang.String output)Process data due to a flush operation.protected inthandleInput(byte[] buffer, int offset, int length)Handle an input requestprotected voidhandleOutput(java.lang.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)ThisRedirector's subordinatePropertyOutputStreams will not set their respective propertieswhile (appendProperties && append).voidsetBinaryOutput(boolean b)Whether to consider the output created by the process binary.voidsetCreateEmptyFiles(boolean createEmptyFiles)Whether output and error files should be created even when empty.voidsetError(java.io.File error)Set the file to which standard error is to be redirected.voidsetError(java.io.File[] error)Set the files to which standard error is to be redirected.voidsetErrorEncoding(java.lang.String errorEncoding)Set the error encoding.voidsetErrorFilterChains(java.util.Vector<FilterChain> errorFilterChains)Set the errorFilterChains.voidsetErrorProperty(java.lang.String errorProperty)Property name whose value should be set to the error of the process.voidsetInput(java.io.File input)Set the input to use for the taskvoidsetInput(java.io.File[] input)Set the input to use for the taskvoidsetInputEncoding(java.lang.String inputEncoding)Set the input encoding.voidsetInputFilterChains(java.util.Vector<FilterChain> inputFilterChains)Set the inputFilterChains.voidsetInputString(java.lang.String inputString)Set the string to use as inputvoidsetLogError(boolean logError)Controls whether error output of exec is logged.voidsetLogInputString(boolean logInputString)Set whether to include the value of the input string in log messages.voidsetOutput(java.io.File out)File the output of the process is redirected to.voidsetOutput(java.io.File[] out)Files the output of the process is redirected to.voidsetOutputEncoding(java.lang.String outputEncoding)Set the output encoding.voidsetOutputFilterChains(java.util.Vector<FilterChain> outputFilterChains)Set the outputFilterChains.voidsetOutputProperty(java.lang.String outputProperty)Property name whose value should be set to the output of the process.voidsetProperties()Notify theRedirectorthat 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
-
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)
ThisRedirector's subordinatePropertyOutputStreams will not set their respective propertieswhile (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 inputFilterChains.- Parameters:
inputFilterChains-VectorcontainingFilterChain.
-
setOutputFilterChains
public void setOutputFilterChains(java.util.Vector<FilterChain> outputFilterChains)
Set the outputFilterChains.- Parameters:
outputFilterChains-VectorcontainingFilterChain.
-
setErrorFilterChains
public void setErrorFilterChains(java.util.Vector<FilterChain> errorFilterChains)
Set the errorFilterChains.- Parameters:
errorFilterChains-VectorcontainingFilterChain.
-
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.IOExceptionHandle 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.IOExceptionComplete 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 theRedirectorthat it is now okay to set any output and/or error properties.
-
-