}
@Override
public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMetadata, List<? extends Compressor> decompressors, ClientGetState state, ClientContext context) {
OutputStream output = null;
PipedInputStream pipeIn = new PipedInputStream();
PipedOutputStream pipeOut = new PipedOutputStream();
Bucket data = null;
// FIXME not strictly correct and unnecessary - archive size already checked against ctx.max*Length inside SingleFileFetcher
long maxLen = Math.min(ctx.maxTempLength, ctx.maxOutputLength);
try {
data = context.getBucketFactory(persistent).makeBucket(maxLen);
output = data.getOutputStream();
if(decompressors != null) {
if(logMINOR) Logger.minor(this, "decompressing...");
pipeOut.connect(pipeIn);
DecompressorThreadManager decompressorManager = new DecompressorThreadManager(pipeIn, decompressors, maxLen);
pipeIn = decompressorManager.execute();
ClientGetWorkerThread worker = new ClientGetWorkerThread(new BufferedInputStream(pipeIn), output, null, null, null, false, null, null, null, context.linkFilterExceptionProvider);
worker.start();
streamGenerator.writeTo(pipeOut, context);
decompressorManager.waitFinished();
worker.waitFinished();
} else streamGenerator.writeTo(output, context);
// We want to see anything thrown when these are closed.
output.close(); output = null;
pipeOut.close(); pipeOut = null;
pipeIn.close(); pipeIn = null;
} catch (Throwable t) {
Logger.error(this, "Caught "+t, t);
onFailure(new FetchException(FetchExceptionMode.INTERNAL_ERROR, t), state, context);
return;
} finally {