} else {
wantBinaryBlob = false;
}
blockFetchContext = new FetchContext(fetchContext, FetchContext.SPLITFILE_DEFAULT_BLOCK_MASK, true, null);
if(parent.isCancelled())
throw new FetchException(FetchExceptionMode.CANCELLED);
try {
// Completion via truncation.
if(isFinalFetch && cb instanceof FileGetCompletionCallback &&
(decompressors == null || decompressors.size() == 0) &&
!fetchContext.filterData) {
FileGetCompletionCallback fileCallback = ((FileGetCompletionCallback)cb);
File targetFile = fileCallback.getCompletionFile();
if(targetFile != null) {
callbackCompleteViaTruncation = fileCallback;
fileCompleteViaTruncation = File.createTempFile(targetFile.getName(), ".freenet-tmp", targetFile.getParentFile());
// Storage must actually create the RAF since it knows the length.
} else {
callbackCompleteViaTruncation = null;
fileCompleteViaTruncation = null;
}
} else {
callbackCompleteViaTruncation = null;
fileCompleteViaTruncation = null;
}
// Construct the storage.
ChecksumChecker checker = new CRCChecksumChecker();
storage = new SplitFileFetcherStorage(metadata, this, decompressors, clientMetadata,
topDontCompress, topCompatibilityMode, fetchContext, realTimeFlag, getSalter(),
thisKey, parent.getURI(), isFinalFetch, parent.getClientDetail(checker),
context.random, context.tempBucketFactory,
persistent ? context.persistentRAFFactory : context.tempRAFFactory,
persistent ? context.jobRunner : context.dummyJobRunner,
context.ticker, context.memoryLimitedJobRunner, checker, persistent,
fileCompleteViaTruncation, context.getFileRandomAccessBufferFactory(persistent),
context.getChkFetchScheduler(realTimeFlag).fetchingKeys());
} catch (InsufficientDiskSpaceException e) {
throw new FetchException(FetchExceptionMode.NOT_ENOUGH_DISK_SPACE);
} catch (IOException e) {
Logger.error(this, "Failed to start splitfile fetcher because of disk I/O error?: "+e, e);
throw new FetchException(FetchExceptionMode.BUCKET_ERROR, e);
}
long eventualLength = Math.max(storage.decompressedLength, metadata.uncompressedDataLength());
cb.onExpectedSize(eventualLength, context);
if(metadata.uncompressedDataLength() > 0)
cb.onFinalizedMetadata();
if(eventualLength > 0 && fetchContext.maxOutputLength > 0 && eventualLength > fetchContext.maxOutputLength)
throw new FetchException(FetchExceptionMode.TOO_BIG, eventualLength, true, clientMetadata.getMIMEType());
getter = new SplitFileFetcherGet(this, storage);
raf = storage.getRAF();
if(logMINOR)
Logger.minor(this, "Created "+(persistent?"persistent" : "transient")+" download for "+
thisKey+" on "+raf+" for "+this);