use of org.apache.tools.ant.util.ConcatFileInputStream in project ant by apache.
the class Redirector method createStreams.
/**
* Create the input, error and output streams based on the configuration
* options.
*/
public void createStreams() {
synchronized (outMutex) {
outStreams();
if (alwaysLogOut || outputStream == null) {
final OutputStream outputLog = new LogOutputStream(managingTask, Project.MSG_INFO);
outputStream = (outputStream == null) ? outputLog : new TeeOutputStream(outputLog, outputStream);
}
if ((outputFilterChains != null && outputFilterChains.size() > 0) || !(outputEncoding.equalsIgnoreCase(inputEncoding))) {
try {
final LeadPipeInputStream snk = new LeadPipeInputStream();
snk.setManagingComponent(managingTask);
InputStream outPumpIn = snk;
Reader reader = new InputStreamReader(outPumpIn, inputEncoding);
if (outputFilterChains != null && outputFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
helper.setPrimaryReader(reader);
helper.setFilterChains(outputFilterChains);
reader = helper.getAssembledReader();
}
outPumpIn = new ReaderInputStream(reader, outputEncoding);
final Thread t = new Thread(threadGroup, new StreamPumper(outPumpIn, outputStream, true), "output pumper");
t.setPriority(Thread.MAX_PRIORITY);
outputStream = new PipedOutputStream(snk);
t.start();
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up output stream", eyeOhEx);
}
}
}
synchronized (errMutex) {
errorStreams();
if (alwaysLogErr || errorStream == null) {
final OutputStream errorLog = new LogOutputStream(managingTask, Project.MSG_WARN);
errorStream = (errorStream == null) ? errorLog : new TeeOutputStream(errorLog, errorStream);
}
if ((errorFilterChains != null && errorFilterChains.size() > 0) || !(errorEncoding.equalsIgnoreCase(inputEncoding))) {
try {
final LeadPipeInputStream snk = new LeadPipeInputStream();
snk.setManagingComponent(managingTask);
InputStream errPumpIn = snk;
Reader reader = new InputStreamReader(errPumpIn, inputEncoding);
if (errorFilterChains != null && errorFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
helper.setPrimaryReader(reader);
helper.setFilterChains(errorFilterChains);
reader = helper.getAssembledReader();
}
errPumpIn = new ReaderInputStream(reader, errorEncoding);
final Thread t = new Thread(threadGroup, new StreamPumper(errPumpIn, errorStream, true), "error pumper");
t.setPriority(Thread.MAX_PRIORITY);
errorStream = new PipedOutputStream(snk);
t.start();
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up error stream", eyeOhEx);
}
}
}
synchronized (inMutex) {
// whatever warnings are needed
if (input != null && input.length > 0) {
managingTask.log("Redirecting input from file" + ((input.length == 1) ? "" : "s"), Project.MSG_VERBOSE);
try {
inputStream = new ConcatFileInputStream(input);
} catch (final IOException eyeOhEx) {
throw new BuildException(eyeOhEx);
}
((ConcatFileInputStream) inputStream).setManagingComponent(managingTask);
} else if (inputString != null) {
final StringBuffer buf = new StringBuffer("Using input ");
if (logInputString) {
buf.append('"').append(inputString).append('"');
} else {
buf.append("string");
}
managingTask.log(buf.toString(), Project.MSG_VERBOSE);
inputStream = new ByteArrayInputStream(inputString.getBytes());
}
if (inputStream != null && inputFilterChains != null && inputFilterChains.size() > 0) {
final ChainReaderHelper helper = new ChainReaderHelper();
helper.setProject(managingTask.getProject());
try {
helper.setPrimaryReader(new InputStreamReader(inputStream, inputEncoding));
} catch (final IOException eyeOhEx) {
throw new BuildException("error setting up input stream", eyeOhEx);
}
helper.setFilterChains(inputFilterChains);
inputStream = new ReaderInputStream(helper.getAssembledReader(), inputEncoding);
}
}
}
Aggregations