use of org.knime.base.filehandling.remote.files.ConnectionMonitor in project GenericKnimeNodes by genericworkflownodes.
the class MimeDirectoryImporterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
// Create connection monitor
final ConnectionMonitor<? extends Connection> monitor = new ConnectionMonitor<>();
// Create output URI container
final List<URIContent> uris = new ArrayList<URIContent>();
try {
URI directoryUri;
if (m_connectionInformation != null) {
exec.setProgress("Connecting to " + m_connectionInformation.toURI());
// Generate URI to the directory
directoryUri = new URI(m_connectionInformation.toURI().toString() + NodeUtils.encodePath(m_configuration.getDirectory()));
} else {
// Create local URI
directoryUri = new File(m_configuration.getDirectory()).toURI();
}
// Create remote file for directory selection
final RemoteFile<? extends Connection> file = RemoteFileFactory.createRemoteFile(directoryUri, m_connectionInformation, monitor);
// List the selected directory
exec.setProgress("Retrieving list of files");
listDirectory(file, uris, true, exec, new MutableInteger(0), new MutableInteger(0));
} finally {
// Close connections
monitor.closeAll();
}
return new PortObject[] { new URIPortObject(uris) };
}
Aggregations