Search in sources :

Example 1 with Filter

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());
}
Also used : Path(ch.cyberduck.core.Path) Read(ch.cyberduck.core.features.Read) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) DefaultLocalTouchFeature(ch.cyberduck.core.local.DefaultLocalTouchFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) ListService(ch.cyberduck.core.ListService) TemporaryFileServiceFactory(ch.cyberduck.core.local.TemporaryFileServiceFactory) ProtocolFactory(ch.cyberduck.core.ProtocolFactory) Filter(ch.cyberduck.core.Filter) Local(ch.cyberduck.core.Local) ConcurrentException(org.apache.commons.lang3.concurrent.ConcurrentException) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) PathAttributes(ch.cyberduck.core.PathAttributes) OutputStream(java.io.OutputStream) Session(ch.cyberduck.core.Session) AttributedList(ch.cyberduck.core.AttributedList) Set(java.util.Set) IOException(java.io.IOException) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) BackgroundException(ch.cyberduck.core.exception.BackgroundException) Collectors(java.util.stream.Collectors) LazyInitializer(org.apache.commons.lang3.concurrent.LazyInitializer) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) IOUtils(org.apache.commons.io.IOUtils) Logger(org.apache.logging.log4j.Logger) Path(ch.cyberduck.core.Path) Pattern(java.util.regex.Pattern) LogManager(org.apache.logging.log4j.LogManager) InputStream(java.io.InputStream) LazyInitializer(org.apache.commons.lang3.concurrent.LazyInitializer) DelegatingHomeFeature(ch.cyberduck.core.shared.DelegatingHomeFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) DefaultPathHomeFeature(ch.cyberduck.core.shared.DefaultPathHomeFeature) IOException(java.io.IOException) ListService(ch.cyberduck.core.ListService) Read(ch.cyberduck.core.features.Read) DefaultLocalTouchFeature(ch.cyberduck.core.local.DefaultLocalTouchFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) BackgroundException(ch.cyberduck.core.exception.BackgroundException) ConcurrentException(org.apache.commons.lang3.concurrent.ConcurrentException)

Aggregations

AttributedList (ch.cyberduck.core.AttributedList)1 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)1 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)1 Filter (ch.cyberduck.core.Filter)1 ListService (ch.cyberduck.core.ListService)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 PathAttributes (ch.cyberduck.core.PathAttributes)1 ProtocolFactory (ch.cyberduck.core.ProtocolFactory)1 Session (ch.cyberduck.core.Session)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 Read (ch.cyberduck.core.features.Read)1 DefaultLocalTouchFeature (ch.cyberduck.core.local.DefaultLocalTouchFeature)1 TemporaryFileServiceFactory (ch.cyberduck.core.local.TemporaryFileServiceFactory)1 DefaultPathHomeFeature (ch.cyberduck.core.shared.DefaultPathHomeFeature)1 DelegatingHomeFeature (ch.cyberduck.core.shared.DelegatingHomeFeature)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1