Search in sources :

Example 26 with NodeSettings

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

the class SerializeUtilTest method testStoreAndLoadJavaToDataCell.

@Test
public void testStoreAndLoadJavaToDataCell() throws InvalidSettingsException {
    Optional<JavaToDataCellConverterFactory<Integer>> factory = JavaToDataCellConverterRegistry.getInstance().getConverterFactories(Integer.class, IntCell.TYPE).stream().findFirst();
    assumeTrue(factory.isPresent());
    final NodeSettings testSettings = new NodeSettings(getClass().getName());
    SerializeUtil.storeConverterFactory(factory.get(), testSettings, "the-factory2");
    final Optional<JavaToDataCellConverterFactory<?>> loadedFactory = SerializeUtil.loadJavaToDataCellConverterFactory(testSettings, "the-factory2");
    assertTrue(loadedFactory.isPresent());
    assertEquals(factory.get(), loadedFactory.get());
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) JavaToDataCellConverterFactory(org.knime.core.data.convert.datacell.JavaToDataCellConverterFactory) Test(org.junit.Test)

Example 27 with NodeSettings

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

the class SerializeUtilTest method testPlaceholders.

@Test
public void testPlaceholders() throws InvalidSettingsException {
    final NodeSettings testSettings = new NodeSettings(getClass().getName());
    final DefinitelyNotRegisteredFactory theMissingFactory = new DefinitelyNotRegisteredFactory();
    SerializeUtil.storeConverterFactory(theMissingFactory, testSettings, "missing-factory");
    Optional<DataCellToJavaConverterFactory<?, ?>> missingFactory = SerializeUtil.loadDataCellToJavaConverterFactory(testSettings, "missing-factory");
    assertFalse(missingFactory.isPresent());
    final FactoryPlaceholder placeholder = SerializeUtil.getPlaceholder(testSettings, "missing-factory");
    assertEquals(theMissingFactory.getName(), placeholder.getName());
    assertEquals(theMissingFactory.getSourceType().getName(), placeholder.getSourceTypeName());
    assertEquals(theMissingFactory.getDestinationType().getName(), placeholder.getDestinationTypeName());
    assertEquals(theMissingFactory.getIdentifier(), placeholder.getIdentifier());
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FactoryPlaceholder(org.knime.core.data.convert.util.SerializeUtil.FactoryPlaceholder) SimpleDataCellToJavaConverterFactory(org.knime.core.data.convert.java.SimpleDataCellToJavaConverterFactory) DataCellToJavaConverterFactory(org.knime.core.data.convert.java.DataCellToJavaConverterFactory) Test(org.junit.Test)

Example 28 with NodeSettings

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

the class SerializeUtilTest method testStoreAndLoadDataCellToJava.

@Test
public void testStoreAndLoadDataCellToJava() throws InvalidSettingsException {
    final Optional<? extends DataCellToJavaConverterFactory<? extends DataValue, Integer>> factory = DataCellToJavaConverterRegistry.getInstance().getConverterFactories(IntCell.TYPE, Integer.class).stream().findFirst();
    assumeTrue(factory.isPresent());
    final NodeSettings testSettings = new NodeSettings(getClass().getName());
    SerializeUtil.storeConverterFactory(factory.get(), testSettings, "the-factory");
    final Optional<DataCellToJavaConverterFactory<?, ?>> loadedFactory = SerializeUtil.loadDataCellToJavaConverterFactory(testSettings, "the-factory");
    assertTrue(loadedFactory.isPresent());
    assertEquals(factory.get(), loadedFactory.get());
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) SimpleDataCellToJavaConverterFactory(org.knime.core.data.convert.java.SimpleDataCellToJavaConverterFactory) DataCellToJavaConverterFactory(org.knime.core.data.convert.java.DataCellToJavaConverterFactory) Test(org.junit.Test)

Example 29 with NodeSettings

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

the class Buffer method closeInternal.

/**
 * Closes by creating shortcut array for file access.
 */
void closeInternal() {
    assert Thread.holdsLock(this);
    // everything is in the list, i.e. in memory
    if (m_outputWriter == null) {
        // disallow modification
        List<BlobSupportDataRow> newList = Collections.unmodifiableList(m_list);
        m_list = newList;
        if (!m_list.isEmpty()) {
            registerMemoryAlertListener();
        }
    } else {
        try {
            flushBuffer();
            m_outputWriter.close();
            NodeSettings nodeSettings = new NodeSettings("table-format-meta-info");
            m_outputWriter.writeMetaInfoAfterWrite(nodeSettings);
            m_list = null;
            double sizeInMB = m_binFile.length() / (double) (1 << 20);
            String size = NumberFormat.getInstance().format(sizeInMB);
            LOGGER.debug("Buffer file (" + m_binFile.getAbsolutePath() + ") is " + size + "MB in size");
            initOutputReader(nodeSettings, IVERSION);
        } catch (IOException ioe) {
            throw new RuntimeException("Cannot close stream of file \"" + m_binFile.getName() + "\"", ioe);
        } catch (InvalidSettingsException ex) {
            throw new RuntimeException("Cannot init reader after buffer is closed", ex);
        }
    }
    m_localRepository = null;
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IOException(java.io.IOException)

Example 30 with NodeSettings

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

the class SetOperatorNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    if (m_enableHilite.getBooleanValue()) {
        final NodeSettings config0 = new NodeSettings("hilite_mapping");
        final DefaultHiLiteMapper mapper0 = (DefaultHiLiteMapper) m_trans0.getMapper();
        if (mapper0 != null) {
            mapper0.save(config0);
        }
        config0.saveToXML(new FileOutputStream(new File(nodeInternDir, HILITE_MAPPING0)));
        final NodeSettings config1 = new NodeSettings("hilite_mapping");
        final DefaultHiLiteMapper mapper1 = (DefaultHiLiteMapper) m_trans1.getMapper();
        if (mapper1 != null) {
            mapper1.save(config1);
        }
        config1.saveToXML(new FileOutputStream(new File(nodeInternDir, HILITE_MAPPING1)));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Aggregations

NodeSettings (org.knime.core.node.NodeSettings)156 File (java.io.File)58 FileOutputStream (java.io.FileOutputStream)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)37 GZIPOutputStream (java.util.zip.GZIPOutputStream)27 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)17 Test (org.junit.Test)16 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)16 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)16 IOException (java.io.IOException)14 OutputStream (java.io.OutputStream)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 BufferedOutputStream (java.io.BufferedOutputStream)9 Map (java.util.Map)8 RowKey (org.knime.core.data.RowKey)8 Config (org.knime.core.node.config.Config)8 LinkedHashMap (java.util.LinkedHashMap)7 DataTableSpec (org.knime.core.data.DataTableSpec)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 ArrayList (java.util.ArrayList)5