Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs

public Class Redirector

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .ByteArrayInputStream, .ByteArrayOutputStream, .File, .IOException, .InputStream, .InputStreamReader, .OutputStream, .PipedOutputStream, .PrintStream, .Reader, .StringReader, java.util.Arrays, .Vector, java.util.stream.Collectors, org.apache.tools.ant.BuildException, .Project, .ProjectComponent, .Task, org.apache.tools.ant.filters.util.ChainReaderHelper, org.apache.tools.ant.types.FilterChain, org.apache.tools.ant.util.ConcatFileInputStream, .FileUtils, .KeepAliveOutputStream, .LazyFileOutputStream, .LeadPipeInputStream, .LineOrientedOutputStreamRedirector, .NullOutputStream, .OutputStreamFunneler, .ReaderInputStream, .TeeOutputStream

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
alwaysLogOut

Flag which indicates that output should be always sent to the log

private boolean
private boolean
appendOut

Flag which indicates if error and output files are to be appended.

private boolean
appendProperties

Whether to complete properties settings

private Redirector.PropertyOutputStream
baos

Buffer used to capture output for storage into a property

private boolean
private boolean
createEmptyFilesOut

Flag which indicates whether files should be created even when empty.

private static final String
private boolean
private boolean
discardOut

Flag which indicates if error and output files are to be discarded.

private final Object
errMutex

Mutex for err

private File[]
error

The file(s) to which standard error is being redirected

private Redirector.PropertyOutputStream
errorBaos

Buffer used to capture error output for storage into a property

private String
errorEncoding

The error encoding

private Vector<FilterChain>
errorFilterChains

The error filter chains

private PrintStream
errorPrintStream

Stream which is used for line oriented error output

private String
errorProperty

The name of the property into which error output is to be stored

private OutputStream
errorStream

The stream for error output

private final Object
inMutex

Mutex for in

private File[]
input

The file(s) from which standard input is being taken.

private String
inputEncoding

The input encoding

private Vector<FilterChain>
inputFilterChains

The input filter chains

private InputStream
inputStream

The stream for input

private String
inputString

String from which input is taken

private boolean
logError

Indicates if standard error should be logged to Ant's log system rather than the output.

private boolean
logInputString

whether to log the inputstring

private final ProjectComponent
managingTask

The task for which this redirector is working

private File[]
out

The file(s) receiving standard output.

private final Object
outMutex

Mutex for out

private PrintStream
outPrintStream

Stream which is used for line oriented output

private String
outputEncoding

The output encoding

private Vector<FilterChain>
outputFilterChains

The output filter chains

private boolean
outputIsBinary

Is the output binary or can we safely split it into lines?

private String
outputProperty

The name of the property into which output is to be stored

private OutputStream
outputStream

The stream for output data

private static final int
private final ThreadGroup
threadGroup

The thread group used for starting StreamPumper threads

Constructor Summary

AccessConstructor and Description
public
Redirector(final Task
the task for which the redirector is to work
managingTask
)

Create a redirector instance for the given task

public
Redirector(final ProjectComponent
the project component for which the redirector is to work
managingTask
)

Create a redirector instance for the given task

Method Summary

Modifier and TypeMethod and Description
public void
complete()

Complete redirection.

public ExecuteStreamHandler

Returns:

the execute stream handler to manage the input, output and error streams.
createHandler
()

Create the StreamHandler to use with our Execute instance.

public void
createStreams()

Create the input, error and output streams based on the configuration options.

private void
private OutputStream
foldFiles(final File[] file, final String logHead, final int loglevel, final boolean append, final boolean createEmptyFiles)

public OutputStream

Returns:

the redirector's error stream or null if no output has been configured
getErrorStream
()

Get the error stream for the redirector

public InputStream

Returns:

the redirector's input stream or null if no output has been configured
getInputStream
()

Get the input stream for the redirector

public OutputStream

Returns:

the redirector's output stream or null if no output has been configured
getOutputStream
()

Get the output stream for the redirector

protected void
handleErrorFlush(final String
the error information being flushed.
output
)

Handle a flush operation on the error stream

protected void
handleErrorOutput(final String
the error output data.
output
)

Process error output

protected void
handleFlush(final String
the data being flushed.
output
)

Process data due to a flush operation.

protected int

Returns:

the number of bytes read
handleInput
(final byte[]
the buffer into which data is to be read.
buffer
,
final int
the offset into the buffer at which data is stored.
offset
,
final int
the amount of data to read
length
)

Handle an input request

protected void
handleOutput(final String
the data to be output
output
)

Pass output sent to System.out to specified output.

private void
outStreams()

outStreams

public void
setAlwaysLog(final boolean
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.

public void
setAppend(final boolean
if true output and error streams are appended to their respective files, if specified.
append
)

Whether output should be appended to or overwrite an existing file.

public void
setAppendProperties(final boolean
whether to append properties.
appendProperties
)

This Redirector's subordinate PropertyOutputStreams will not set their respective properties while (appendProperties && append).

public void
setBinaryOutput(final boolean
boolean
b
)

Whether to consider the output created by the process binary.

public void
setCreateEmptyFiles(final boolean
boolean.
createEmptyFiles
)

Whether output and error files should be created even when empty.

public void
setDiscardError(final boolean
if true error streams are discarded.
discard
)

Whether error output should be discarded.

public void
setDiscardOutput(final boolean
if true output streams are discarded.
discard
)

Whether output should be discarded.

public void
setError(final File
the file to which error is to be written
error
)

Set the file to which standard error is to be redirected.

public void
setError(final File[]
the file to which error is to be written
error
)

Set the files to which standard error is to be redirected.

public void
setErrorEncoding(final String
String.
errorEncoding
)

Set the error encoding.

public void
setErrorFilterChains(final Vector<FilterChain>
Vector containing FilterChain.
errorFilterChains
)

Set the error FilterChains.

public void
setErrorProperty(final String
the name of the property to be set with the error output.
errorProperty
)

Property name whose value should be set to the error of the process.

public void
setInput(final File
the file from which input is read.
input
)

Set the input to use for the task

public void
setInput(final File[]
the files from which input is read.
input
)

Set the input to use for the task

public void
setInputEncoding(final String
String.
inputEncoding
)

Set the input encoding.

public void
setInputFilterChains(final Vector<FilterChain>
Vector containing FilterChain.
inputFilterChains
)

Set the input FilterChains.

pack-priv void
setInputStream(final InputStream
the stream from which input will be read
inputStream
)

Set a stream to use as input.

public void
setInputString(final String
the string which is used as the input source
inputString
)

Set the string to use as input

public void
setLogError(final boolean
if true the standard error is sent to the Ant log system and not sent to output.
logError
)

Controls whether error output of exec is logged.

public void
setLogInputString(final boolean
true or false.
logInputString
)

Set whether to include the value of the input string in log messages.

public void
setOutput(final File
the file to which output stream is written
out
)

File the output of the process is redirected to.

public void
setOutput(final File[]
the files to which output stream is written
out
)

Files the output of the process is redirected to.

public void
setOutputEncoding(final String
String.
outputEncoding
)

Set the output encoding.

public void
setOutputFilterChains(final Vector<FilterChain>
Vector containing FilterChain.
outputFilterChains
)

Set the output FilterChains.

public void
setOutputProperty(final String
the name of the property to be set with the task's output.
outputProperty
)

Property name whose value should be set to the output of the process.

public void
setProperties()

Notify the Redirector that it is now okay to set any output and/or error properties.

private void
setPropertyFromBAOS(final ByteArrayOutputStream
contains the property value.
baos
,
final String
the property name.
propertyName
)

Set a property from a ByteArrayOutputStream

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

alwaysLogErrback to summary
private boolean alwaysLogErr
alwaysLogOutback to summary
private boolean alwaysLogOut

Flag which indicates that output should be always sent to the log

appendErrback to summary
private boolean appendErr
appendOutback to summary
private boolean appendOut

Flag which indicates if error and output files are to be appended.

appendPropertiesback to summary
private boolean appendProperties

Whether to complete properties settings

baosback to summary
private Redirector.PropertyOutputStream baos

Buffer used to capture output for storage into a property

createEmptyFilesErrback to summary
private boolean createEmptyFilesErr
createEmptyFilesOutback to summary
private boolean createEmptyFilesOut

Flag which indicates whether files should be created even when empty.

DEFAULT_ENCODINGback to summary
private static final String DEFAULT_ENCODING
discardErrback to summary
private boolean discardErr
discardOutback to summary
private boolean discardOut

Flag which indicates if error and output files are to be discarded.

errMutexback to summary
private final Object errMutex

Mutex for err

errorback to summary
private File[] error

The file(s) to which standard error is being redirected

errorBaosback to summary
private Redirector.PropertyOutputStream errorBaos

Buffer used to capture error output for storage into a property

errorEncodingback to summary
private String errorEncoding

The error encoding

errorFilterChainsback to summary
private Vector<FilterChain> errorFilterChains

The error filter chains

errorPrintStreamback to summary
private PrintStream errorPrintStream

Stream which is used for line oriented error output

errorPropertyback to summary
private String errorProperty

The name of the property into which error output is to be stored

errorStreamback to summary
private OutputStream errorStream

The stream for error output

inMutexback to summary
private final Object inMutex

Mutex for in

inputback to summary
private File[] input

The file(s) from which standard input is being taken. If > 1, files' content will be concatenated in the order received.

inputEncodingback to summary
private String inputEncoding

The input encoding

inputFilterChainsback to summary
private Vector<FilterChain> inputFilterChains

The input filter chains

inputStreamback to summary
private InputStream inputStream

The stream for input

inputStringback to summary
private String inputString

String from which input is taken

logErrorback to summary
private boolean logError

Indicates if standard error should be logged to Ant's log system rather than the output. This has no effect if standard error is redirected to a file or property.

logInputStringback to summary
private boolean logInputString

whether to log the inputstring

managingTaskback to summary
private final ProjectComponent managingTask

The task for which this redirector is working

outback to summary
private File[] out

The file(s) receiving standard output. Will also receive standard error unless standard error is redirected or logError is true.

outMutexback to summary
private final Object outMutex

Mutex for out

outPrintStreamback to summary
private PrintStream outPrintStream

Stream which is used for line oriented output

outputEncodingback to summary
private String outputEncoding

The output encoding

outputFilterChainsback to summary
private Vector<FilterChain> outputFilterChains

The output filter chains

outputIsBinaryback to summary
private boolean outputIsBinary

Is the output binary or can we safely split it into lines?

outputPropertyback to summary
private String outputProperty

The name of the property into which output is to be stored

outputStreamback to summary
private OutputStream outputStream

The stream for output data

STREAMPUMPER_WAIT_INTERVALback to summary
private static final int STREAMPUMPER_WAIT_INTERVAL
threadGroupback to summary
private final ThreadGroup threadGroup

The thread group used for starting StreamPumper threads

Constructor Detail

Redirectorback to summary
public Redirector(final Task managingTask)

Create a redirector instance for the given task

Parameters
managingTask:Task

the task for which the redirector is to work

Redirectorback to summary
public Redirector(final ProjectComponent managingTask)

Create a redirector instance for the given task

Parameters
managingTask:ProjectComponent

the project component for which the redirector is to work

Since
Ant 1.6.3

Method Detail

completeback to summary
public void complete() throws IOException

Complete redirection. This operation will close any streams and create any specified property values.

Exceptions
IOException:
if the output properties cannot be read from their output streams.
createHandlerback to summary
public ExecuteStreamHandler createHandler() throws BuildException

Create the StreamHandler to use with our Execute instance.

Returns:ExecuteStreamHandler

the execute stream handler to manage the input, output and error streams.

Exceptions
BuildException:
if the execute stream handler cannot be created.
createStreamsback to summary
public void createStreams()

Create the input, error and output streams based on the configuration options.

errorStreamsback to summary
private void errorStreams()
foldFilesback to summary
private OutputStream foldFiles(final File[] file, final String logHead, final int loglevel, final boolean append, final boolean createEmptyFiles)
getErrorStreamback to summary
public OutputStream getErrorStream()

Get the error stream for the redirector

Returns:OutputStream

the redirector's error stream or null if no output has been configured

getInputStreamback to summary
public InputStream getInputStream()

Get the input stream for the redirector

Returns:InputStream

the redirector's input stream or null if no output has been configured

getOutputStreamback to summary
public OutputStream getOutputStream()

Get the output stream for the redirector

Returns:OutputStream

the redirector's output stream or null if no output has been configured

handleErrorFlushback to summary
protected void handleErrorFlush(final String output)

Handle a flush operation on the error stream

Parameters
output:String

the error information being flushed.

handleErrorOutputback to summary
protected void handleErrorOutput(final String output)

Process error output

Parameters
output:String

the error output data.

handleFlushback to summary
protected void handleFlush(final String output)

Process data due to a flush operation.

Parameters
output:String

the data being flushed.

handleInputback to summary
protected int handleInput(final byte[] buffer, final int offset, final int length) throws IOException

Handle an input request

Parameters
buffer:byte[]

the buffer into which data is to be read.

offset:int

the offset into the buffer at which data is stored.

length:int

the amount of data to read

Returns:int

the number of bytes read

Exceptions
IOException:
if the data cannot be read
handleOutputback to summary
protected void handleOutput(final String output)

Pass output sent to System.out to specified output.

Parameters
output:String

the data to be output

outStreamsback to summary
private void outStreams()

outStreams

setAlwaysLogback to summary
public void setAlwaysLog(final 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

boolean

Since
Ant 1.6.3
setAppendback to summary
public void setAppend(final boolean append)

Whether output should be appended to or overwrite an existing file. Defaults to false.

Parameters
append:boolean

if true output and error streams are appended to their respective files, if specified.

setAppendPropertiesback to summary
public void setAppendProperties(final boolean appendProperties)

This Redirector's subordinate PropertyOutputStreams will not set their respective properties while (appendProperties && append).

Parameters
appendProperties:boolean

whether to append properties.

setBinaryOutputback to summary
public void setBinaryOutput(final 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

boolean

Since
1.9.4
setCreateEmptyFilesback to summary
public void setCreateEmptyFiles(final boolean createEmptyFiles)

Whether output and error files should be created even when empty. Defaults to true.

Parameters
createEmptyFiles:boolean

boolean.

setDiscardErrorback to summary
public void setDiscardError(final boolean discard)

Whether error output should be discarded.

Defaults to false.

Parameters
discard:boolean

if true error streams are discarded.

Since
Ant 1.10.10
See Also
setDiscardOutput
setDiscardOutputback to summary
public void setDiscardOutput(final boolean discard)

Whether output should be discarded.

Defaults to false.

Parameters
discard:boolean

if true output streams are discarded.

Since
Ant 1.10.10
See Also
setDiscardError
setErrorback to summary
public void setError(final File error)

Set the file to which standard error is to be redirected.

Parameters
error:File

the file to which error is to be written

setErrorback to summary
public void setError(final File[] error)

Set the files to which standard error is to be redirected.

Parameters
error:File[]

the file to which error is to be written

setErrorEncodingback to summary
public void setErrorEncoding(final String errorEncoding)

Set the error encoding.

Parameters
errorEncoding:String

String.

setErrorFilterChainsback to summary
public void setErrorFilterChains(final Vector<FilterChain> errorFilterChains)

Set the error FilterChains.

Parameters
errorFilterChains:Vector<FilterChain>

Vector containing FilterChain.

setErrorPropertyback to summary
public void setErrorProperty(final String errorProperty)

Property name whose value should be set to the error of the process.

Parameters
errorProperty:String

the name of the property to be set with the error output.

setInputback to summary
public void setInput(final File input)

Set the input to use for the task

Parameters
input:File

the file from which input is read.

setInputback to summary
public void setInput(final File[] input)

Set the input to use for the task

Parameters
input:File[]

the files from which input is read.

setInputEncodingback to summary
public void setInputEncoding(final String inputEncoding)

Set the input encoding.

Parameters
inputEncoding:String

String.

setInputFilterChainsback to summary
public void setInputFilterChains(final Vector<FilterChain> inputFilterChains)

Set the input FilterChains.

Parameters
inputFilterChains:Vector<FilterChain>

Vector containing FilterChain.

setInputStreamback to summary
pack-priv void setInputStream(final InputStream inputStream)

Set a stream to use as input.

Parameters
inputStream:InputStream

the stream from which input will be read

Since
Ant 1.6.3
setInputStringback to summary
public void setInputString(final String inputString)

Set the string to use as input

Parameters
inputString:String

the string which is used as the input source

setLogErrorback to summary
public void setLogError(final 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:boolean

if true the standard error is sent to the Ant log system and not sent to output.

setLogInputStringback to summary
public void setLogInputString(final boolean logInputString)

Set whether to include the value of the input string in log messages. Defaults to true.

Parameters
logInputString:boolean

true or false.

Since
Ant 1.7
setOutputback to summary
public void setOutput(final 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:File

the file to which output stream is written

setOutputback to summary
public void setOutput(final 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:File[]

the files to which output stream is written

setOutputEncodingback to summary
public void setOutputEncoding(final String outputEncoding)

Set the output encoding.

Parameters
outputEncoding:String

String.

setOutputFilterChainsback to summary
public void setOutputFilterChains(final Vector<FilterChain> outputFilterChains)

Set the output FilterChains.

Parameters
outputFilterChains:Vector<FilterChain>

Vector containing FilterChain.

setOutputPropertyback to summary
public void setOutputProperty(final String outputProperty)

Property name whose value should be set to the output of the process.

Parameters
outputProperty:String

the name of the property to be set with the task's output.

setPropertiesback to summary
public void setProperties()

Notify the Redirector that it is now okay to set any output and/or error properties.

setPropertyFromBAOSback to summary
private void setPropertyFromBAOS(final ByteArrayOutputStream baos, final String propertyName)

Set a property from a ByteArrayOutputStream

Parameters
baos:ByteArrayOutputStream

contains the property value.

propertyName:String

the property name.

org.apache.tools.ant.taskdefs back to summary

private Class Redirector.PropertyOutputStream

extends ByteArrayOutputStream
Class Inheritance

Field Summary

Modifier and TypeField and Description
private boolean
private final String
Inherited from java.io.ByteArrayOutputStream:
bufcount

Constructor Summary

AccessConstructor and Description
pack-priv
PropertyOutputStream(final String property)

Method Summary

Modifier and TypeMethod and Description
public void
close()

Overrides java.io.ByteArrayOutputStream.close.

Implements java.io.Closeable.close.

Closing a ByteArrayOutputStream has no effect.
Inherited from java.io.ByteArrayOutputStream:
resetsizetoByteArraytoStringtoStringtoStringtoStringwritewritewriteByteswriteTo

Field Detail

closedback to summary
private boolean closed
propertyback to summary
private final String property

Constructor Detail

PropertyOutputStreamback to summary
pack-priv PropertyOutputStream(final String property)

Method Detail

closeback to summary
public void close() throws IOException

Overrides java.io.ByteArrayOutputStream.close.

Implements java.io.Closeable.close.

Doc from java.io.ByteArrayOutputStream.close.

Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Annotations
@Override
Exceptions
IOException:

Doc from java.io.OutputStream.close.

if an I/O error occurs.