Search in sources :

Example 76 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class ConcatenateTable method load.

/**
 * Restore table form node settings object.
 * @param s Containing information.
 * @param spec Associated spec.
 * @param tblRep For table lookup
 * @param dataRepository The data repository (needed for blobs, file stores, and table ids).
 * @return The newly instantiated table.
 * @throws InvalidSettingsException If information is invalid.
 * @since 3.7
 */
public static ConcatenateTable load(final NodeSettingsRO s, final DataTableSpec spec, final Map<Integer, BufferedDataTable> tblRep, final WorkflowDataRepository dataRepository) throws InvalidSettingsException {
    NodeSettingsRO subSettings = s.getNodeSettings(CFG_INTERNAL_META);
    int[] referenceIDs = subSettings.getIntArray(CFG_REFERENCE_IDS);
    int rowCount = subSettings.getInt(CFG_ROW_COUNT);
    BufferedDataTable[] tables = new BufferedDataTable[referenceIDs.length];
    for (int i = 0; i < tables.length; i++) {
        tables[i] = BufferedDataTable.getDataTable(tblRep, referenceIDs[i], dataRepository);
    }
    String dupSuffix = subSettings.getString(CFG_DUPLICATE_ROW_KEY_SUFFIX, null);
    return new ConcatenateTable(tables, dupSuffix, rowCount);
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 77 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class CopyOnAccessTask method createBuffer.

/**
 * Called to start the copy process. Is only called once.
 * @param in To read from, will instantiate a zip input stream on top of
 * it, which will call close() eventually
 * @return The buffer instance reading from the temp file.
 * @throws IOException If the file can't be accessed.
 */
Buffer createBuffer(final InputStream in) throws IOException {
    ZipInputStream inStream = new ZipInputStream(in);
    ZipEntry entry;
    // file name ending may change later when meta info is read
    final String fallbackFileExtension = ".tmp";
    File binFile = DataContainer.createTempFile(fallbackFileExtension);
    File blobDir = null;
    File fileStoreDir = null;
    // we only need to read from this file while being in
    // this method; temp file is deleted later on.
    File metaTempFile = FileUtil.createTempFile("meta", ".xml", true);
    DataTableSpec spec = m_spec;
    boolean isSpecFound = m_spec != null;
    boolean isDataFound = false;
    boolean isMetaFound = false;
    while ((entry = inStream.getNextEntry()) != null) {
        String name = entry.getName();
        if (name.equals(Buffer.ZIP_ENTRY_DATA)) {
            try (OutputStream output = new BufferedOutputStream(new FileOutputStream(binFile))) {
                FileUtil.copy(inStream, output);
            }
            inStream.closeEntry();
            isDataFound = true;
        } else if (name.equals(Buffer.ZIP_ENTRY_META)) {
            try (OutputStream output = new BufferedOutputStream(new FileOutputStream(metaTempFile))) {
                FileUtil.copy(inStream, output);
            }
            inStream.closeEntry();
            isMetaFound = true;
        } else if (name.startsWith(Buffer.ZIP_ENTRY_BLOBS)) {
            if (blobDir == null) {
                blobDir = Buffer.createBlobDirNameForTemp(binFile);
            }
            copyEntryToDir(entry, inStream, blobDir);
        } else if (name.startsWith(Buffer.ZIP_ENTRY_FILESTORES)) {
            if (fileStoreDir == null) {
                fileStoreDir = FileUtil.createTempDir("knime_fs_datacontainer-");
            }
            copyEntryToDir(entry, inStream, fileStoreDir);
        } else if (name.equals(BufferedDataContainerDelegate.ZIP_ENTRY_SPEC) && !isSpecFound) {
            InputStream nonClosableStream = new NonClosableInputStream.Zip(inStream);
            NodeSettingsRO settings = NodeSettings.loadFromXML(nonClosableStream);
            try {
                NodeSettingsRO specSettings = settings.getNodeSettings(BufferedDataContainerDelegate.CFG_TABLESPEC);
                spec = DataTableSpec.load(specSettings);
                isSpecFound = true;
            } catch (InvalidSettingsException ise) {
                IOException ioe = new IOException("Unable to read spec from file");
                ioe.initCause(ise);
                throw ioe;
            }
        }
    }
    inStream.close();
    if (!isDataFound) {
        throw new IOException("No entry " + Buffer.ZIP_ENTRY_DATA + " in file");
    }
    if (!isMetaFound) {
        throw new IOException("No entry " + Buffer.ZIP_ENTRY_META + " in file");
    }
    if (!isSpecFound) {
        throw new IOException("No entry " + BufferedDataContainerDelegate.ZIP_ENTRY_SPEC + " in file");
    }
    InputStream metaIn = new BufferedInputStream(new FileInputStream(metaTempFile));
    Buffer buffer = m_bufferCreator.createBuffer(binFile, blobDir, fileStoreDir, spec, metaIn, m_bufferID, m_dataRepository);
    // }
    if (m_needsRestoreIntoMemory) {
        buffer.setRestoreIntoMemoryOnCacheMiss();
    }
    metaIn.close();
    metaTempFile.delete();
    return buffer;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) NonClosableInputStream(org.knime.core.data.util.NonClosableInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ZipInputStream(java.util.zip.ZipInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 78 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class TableSpecReplacerTable method load11x.

/**
 * Restores table from a file that has been written using KNIME 1.1.x
 * or before. Not intended to be used by node implementations.
 * @param f The file to read from.
 * @param s The settings to get meta information from.
 * @param tblRep The table repository
 * @param dataRepository The data repository (needed for blobs, file stores, and table ids).
 * @return The resulting table.
 * @throws IOException If reading the file fails.
 * @throws InvalidSettingsException If reading the settings fails.
 * @since 3.7
 */
public static TableSpecReplacerTable load11x(final File f, final NodeSettingsRO s, final Map<Integer, BufferedDataTable> tblRep, final WorkflowDataRepository dataRepository) throws IOException, InvalidSettingsException {
    try (ZipFile zipFile = new ZipFile(f);
        InputStream in = new BufferedInputStream(zipFile.getInputStream(new ZipEntry(ZIP_ENTRY_SPEC)))) {
        NodeSettingsRO specSettings = NodeSettings.loadFromXML(in);
        DataTableSpec newSpec = DataTableSpec.load(specSettings);
        return load(s, newSpec, tblRep, dataRepository);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ZipFile(java.util.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 79 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class NodeExecutionJobManagerPool method load.

/**
 * Updates the settings of the passed job manager - if the settings specify
 * the same type of job manager - or creates and returns a new instance of
 * that new type of job manager.
 *
 * @param instance the "old" job manager that will be updated if its type
 *            fits the type in the settings, or null to create a new
 *            instance.
 * @param ncSettings the new settings to apply
 * @return either the specified instance with new settings, or a new
 *         instance of a new type with the new settings.
 * @throws InvalidSettingsException if the settings are invalid
 */
public static NodeExecutionJobManager load(final NodeExecutionJobManager instance, final NodeSettingsRO ncSettings) throws InvalidSettingsException {
    if (instance == null) {
        // create a new instance then.
        return load(ncSettings);
    }
    String jobManagerID = ncSettings.getString(CFG_JOB_MANAGER_FACTORY_ID);
    if (!instance.getID().equals(jobManagerID)) {
        // The settings request a different job manager: create it then.
        return load(ncSettings);
    }
    NodeSettingsRO sub = ncSettings.getNodeSettings(CFG_JOB_MANAGER_SETTINGS);
    instance.load(sub);
    return instance;
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Example 80 with NodeSettingsRO

use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.

the class TypeFilterConfigurationImpl method loadConfigurationInModel.

/**
 * Loads the configuration from the given settings object. Fails if not valid.
 *
 * @param settings Settings object containing the configuration.
 * @throws InvalidSettingsException If settings are invalid
 */
void loadConfigurationInModel(final NodeSettingsRO settings) throws InvalidSettingsException {
    m_selections.clear();
    NodeSettingsRO typeListSettings = settings.getNodeSettings(CFG_TYPELIST);
    for (String key : typeListSettings.keySet()) {
        m_selections.put(key, typeListSettings.getBoolean(key, false));
    }
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8