use of ch.cyberduck.core.Filter in project cyberduck by iterate-ch.
the class RemoteProfilesFinder method find.
@Override
public Set<ProfileDescription> find(final Visitor visitor) throws BackgroundException {
if (log.isInfoEnabled()) {
log.info(String.format("Fetch profiles from %s", session.getHost()));
}
final ProfileFilter filter = new ProfileFilter();
final AttributedList<Path> list = session.getFeature(ListService.class).list(new DelegatingHomeFeature(new DefaultPathHomeFeature(session.getHost())).find(), new DisabledListProgressListener());
return list.filter(filter).toStream().map(file -> visitor.visit(new RemoteProfileDescription(protocols, file, new LazyInitializer<Local>() {
@Override
protected Local initialize() throws ConcurrentException {
try {
final Read read = session.getFeature(Read.class);
if (log.isInfoEnabled()) {
log.info(String.format("Download profile %s", file));
}
final InputStream in = read.read(file.withAttributes(new PathAttributes(file.attributes()).withVersionId(null)), new TransferStatus().withLength(TransferStatus.UNKNOWN_LENGTH), new DisabledConnectionCallback());
final Local temp = TemporaryFileServiceFactory.get().create(file.getName());
new DefaultLocalTouchFeature().touch(temp);
final OutputStream out = temp.getOutputStream(false);
try {
IOUtils.copy(in, out);
} finally {
in.close();
out.close();
}
return temp;
} catch (BackgroundException | IOException e) {
throw new ConcurrentException(e);
}
}
}))).collect(Collectors.toSet());
}
Aggregations