use of org.syncany.operations.Downloader in project syncany by syncany.
the class GetFileFolderRequestHandler method handleRequest.
@Override
public Response handleRequest(FolderRequest request) {
GetFileFolderRequest concreteRequest = (GetFileFolderRequest) request;
try {
FileHistoryId fileHistoryId = FileHistoryId.parseFileId(concreteRequest.getFileHistoryId());
long version = concreteRequest.getVersion();
FileVersion fileVersion = localDatabase.getFileVersion(fileHistoryId, version);
FileContent fileContent = localDatabase.getFileContent(fileVersion.getChecksum(), true);
Map<ChunkChecksum, MultiChunkId> multiChunks = localDatabase.getMultiChunkIdsByChecksums(fileContent.getChunks());
TransferManager transferManager = config.getTransferPlugin().createTransferManager(config.getConnection(), config);
Downloader downloader = new Downloader(config, transferManager);
Assembler assembler = new Assembler(config, localDatabase);
downloader.downloadAndDecryptMultiChunks(new HashSet<MultiChunkId>(multiChunks.values()));
File tempFile = assembler.assembleToCache(fileVersion);
String tempFileToken = StringUtil.toHex(ObjectId.secureRandomBytes(40));
GetFileFolderResponse fileResponse = new GetFileFolderResponse(concreteRequest.getId(), concreteRequest.getRoot(), tempFileToken);
GetFileFolderResponseInternal fileResponseInternal = new GetFileFolderResponseInternal(fileResponse, tempFile);
eventBus.post(fileResponseInternal);
return null;
} catch (Exception e) {
logger.log(Level.WARNING, "Cannot reassemble file.", e);
return new BadRequestResponse(concreteRequest.getId(), "Cannot reassemble file.");
}
}
Aggregations