Search in sources :

Example 56 with ReferencedFile

use of org.knime.core.internal.ReferencedFile in project knime-core by knime.

the class NativeNodeContainer method pushNodeDropDirURLsOntoStack.

/**
 * Support old-style drop dir mechanism - replaced since 2.8 with relative mountpoints,
 * e.g. knime://knime.workflow
 */
private void pushNodeDropDirURLsOntoStack(final FlowObjectStack st) {
    ReferencedFile refDir = getNodeContainerDirectory();
    ReferencedFile dropFolder = refDir == null ? null : new ReferencedFile(refDir, DROP_DIR_NAME);
    if (dropFolder == null) {
        return;
    }
    dropFolder.lock();
    try {
        File directory = dropFolder.getFile();
        if (!directory.exists()) {
            return;
        }
        String[] files = directory.list();
        if (files != null) {
            StringBuilder debug = new StringBuilder("Found " + files.length + " node local file(s) to " + getNameWithID() + ": ");
            debug.append(Arrays.toString(Arrays.copyOf(files, Math.max(3, files.length))));
            for (String f : files) {
                File child = new File(directory, f);
                try {
                    st.push(new FlowVariable(Scope.Local.getPrefix() + "(drop) " + f, // child.getAbsolutePath(), Scope.Local));
                    child.toURI().toURL().toString(), Scope.Local));
                // } catch (Exception mue) {
                } catch (MalformedURLException mue) {
                    LOGGER.warn("Unable to process drop file", mue);
                }
            }
        }
    } finally {
        dropFolder.unlock();
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 57 with ReferencedFile

use of org.knime.core.internal.ReferencedFile in project knime-core by knime.

the class FileWorkflowPersistor method loadNodeFile.

ReferencedFile loadNodeFile(final NodeSettingsRO settings, final ReferencedFile workflowDirRef) throws InvalidSettingsException {
    String fileString = settings.getString("node_settings_file");
    if (fileString == null) {
        throw new InvalidSettingsException("Unable to read settings " + "file for node " + settings.getKey());
    }
    File workflowDir = workflowDirRef.getFile();
    // fileString is something like "File Reader(#1)/settings.xml", thus
    // it contains two levels of the hierarchy. We leave it here to the
    // java.io.File implementation to resolve these levels
    File fullFile = new File(workflowDir, fileString);
    if (!fullFile.isFile() || !fullFile.canRead()) {
        throw new InvalidSettingsException("Unable to read settings " + "file " + fullFile.getAbsolutePath());
    }
    Stack<String> children = new Stack<String>();
    File workflowDirAbsolute = workflowDir.getAbsoluteFile();
    while (!fullFile.getAbsoluteFile().equals(workflowDirAbsolute)) {
        children.push(fullFile.getName());
        fullFile = fullFile.getParentFile();
    }
    // create a ReferencedFile hierarchy for the settings file
    ReferencedFile result = workflowDirRef;
    while (!children.empty()) {
        result = new ReferencedFile(result, children.pop());
    }
    return result;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) ReferencedFile(org.knime.core.internal.ReferencedFile) Stack(java.util.Stack)

Example 58 with ReferencedFile

use of org.knime.core.internal.ReferencedFile in project knime-core by knime.

the class NodeContainer method unsetDirty.

/**
 * Called from persistor when node has been saved.
 */
void unsetDirty() {
    final ReferencedFile ncDirectory = getNodeContainerDirectory();
    assert ncDirectory != null : "NC directory must not be null at this point";
    ncDirectory.setDirty(false);
    getChangesTracker().ifPresent(ct -> ct.clearChanges());
}
Also used : ReferencedFile(org.knime.core.internal.ReferencedFile)

Aggregations

ReferencedFile (org.knime.core.internal.ReferencedFile)58 File (java.io.File)35 IOException (java.io.IOException)28 BufferedInputStream (java.io.BufferedInputStream)15 FileInputStream (java.io.FileInputStream)14 PortObject (org.knime.core.node.port.PortObject)12 FlowVariablePortObject (org.knime.core.node.port.flowvariable.FlowVariablePortObject)12 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)11 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)10 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)10 InactiveBranchPortObject (org.knime.core.node.port.inactive.InactiveBranchPortObject)10 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)8 FlowVariablePortObjectSpec (org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)8 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)8 InactiveBranchPortObjectSpec (org.knime.core.node.port.inactive.InactiveBranchPortObjectSpec)7 FileOutputStream (java.io.FileOutputStream)6 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)6 NodeSettings (org.knime.core.node.NodeSettings)6 DataTableSpec (org.knime.core.data.DataTableSpec)5