{
validateInput(INPUT);
validateOutput(OUTPUT);
mInput = getInput();
mOutput = getOutput();
final GrowableInMemoryPipe pipe = new GrowableInMemoryPipe();
Thread writeThread = new Thread(new Runnable() {
@Override
public void run()
{
try
{
Object block;
while ((block = pipe.read()) != ControlBlock.NO_MORE_DATA)
{
mOutput.write(block);
}
}
catch (PipeClosedException e)
{
pipe.closeForReading();
}
catch (PipeIOException e)
{
mOutputError = e;
pipe.closeForReading();
mOutput.closeForWritingDueToError();
}
catch (DataError e)
{
mOutputError = e;
mOutput.closeForWritingDueToError();
}
catch (PipeTerminatedException e)
{
mOutputError = e;
pipe.closeForReading();
mOutput.closeForWriting();
}
}
});
writeThread.start();
try
{
Object block;
while ((block = mInput.read()) != ControlBlock.NO_MORE_DATA)
{
pipe.write(block);
}
pipe.closeForWriting();
writeThread.join();
}
catch (PipeClosedException e)
{
if (mOutputError instanceof ActivityUserException)
{
throw (ActivityUserException)mOutputError;
}
if (mOutputError instanceof ActivityProcessingException)
{
throw (ActivityProcessingException)mOutputError;
}
if (mOutputError instanceof ActivityTerminatedException)
{
throw (ActivityTerminatedException)mOutputError;
}
return;
}
catch (PipeIOException e)
{
pipe.closeForWritingDueToError();
throw new ActivityProcessingException(e);
}
catch (PipeTerminatedException e)
{
pipe.closeForWriting();
throw new ActivityTerminatedException();
}
catch (InterruptedException e)
{
Thread.currentThread().interrupt();