Search in sources :

Example 6 with URIPortObject

use of org.knime.core.data.uri.URIPortObject 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) };
}
Also used : URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) MutableInteger(org.knime.core.util.MutableInteger) ConnectionMonitor(org.knime.base.filehandling.remote.files.ConnectionMonitor) ArrayList(java.util.ArrayList) URI(java.net.URI) RemoteFile(org.knime.base.filehandling.remote.files.RemoteFile) File(java.io.File) URIPortObject(org.knime.core.data.uri.URIPortObject) ConnectionInformationPortObject(org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) PortObject(org.knime.core.node.port.PortObject) URIContent(org.knime.core.data.uri.URIContent)

Example 7 with URIPortObject

use of org.knime.core.data.uri.URIPortObject in project GenericKnimeNodes by genericworkflownodes.

the class MimeFileImporterNodeModel method execute.

@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception {
    File file = new File(convertToURL(m_filename).toURI());
    if (!file.exists()) {
        throw new Exception("File does not exist: " + file.getAbsolutePath());
    }
    List<URIContent> uris = new ArrayList<URIContent>();
    uris.add(new URIContent(file.toURI(), (m_file_extension.isActive() ? m_file_extension.getStringValue() : MIMETypeHelper.getMIMEtypeExtension(file.getAbsolutePath()))));
    data = Helper.readFileSummary(file, 50);
    return new PortObject[] { new URIPortObject(uris) };
}
Also used : URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) ArrayList(java.util.ArrayList) ZipFile(java.util.zip.ZipFile) File(java.io.File) URIPortObject(org.knime.core.data.uri.URIPortObject) IURIPortObject(org.knime.core.data.uri.IURIPortObject) PortObject(org.knime.core.node.port.PortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) URIContent(org.knime.core.data.uri.URIContent)

Aggregations

IURIPortObject (org.knime.core.data.uri.IURIPortObject)7 URIPortObject (org.knime.core.data.uri.URIPortObject)7 ArrayList (java.util.ArrayList)6 URIContent (org.knime.core.data.uri.URIContent)6 PortObject (org.knime.core.node.port.PortObject)5 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)4 File (java.io.File)3 FileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.FileStoreURIPortObject)2 PortObjectHandlerCell (com.genericworkflownodes.knime.base.data.port.PortObjectHandlerCell)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 BufferedDataTable (org.knime.core.node.BufferedDataTable)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 AbstractFileStoreURIPortObject (com.genericworkflownodes.knime.base.data.port.AbstractFileStoreURIPortObject)1 URI (java.net.URI)1 ZipFile (java.util.zip.ZipFile)1 ConnectionInformationPortObject (org.knime.base.filehandling.remote.connectioninformation.port.ConnectionInformationPortObject)1 ConnectionMonitor (org.knime.base.filehandling.remote.files.ConnectionMonitor)1 RemoteFile (org.knime.base.filehandling.remote.files.RemoteFile)1 DataRow (org.knime.core.data.DataRow)1