Search in sources :

Example 96 with NodeSettingsWO

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

the class Statistics2Table method save.

/**
 * Saves this object to the given settings object.
 * @param sett this object is saved to
 */
public void save(final NodeSettingsWO sett) {
    m_spec.save(sett.addConfig("spec"));
    sett.addDoubleArray("minimum", m_minValues);
    sett.addDoubleArray("maximum", m_maxValues);
    sett.addDoubleArray("mean", m_meanValues);
    sett.addDoubleArray("variance", m_varianceValues);
    sett.addDoubleArray("median", m_median);
    sett.addDoubleArray("missings", m_missingValueCnt);
    sett.addDoubleArray("sums", m_sum);
    sett.addInt("row_count", m_rowCount);
    for (int c = 0; c < m_nominalValues.length; c++) {
        if (m_nominalValues[c] != null) {
            NodeSettingsWO subSett = sett.addNodeSettings(m_spec.getColumnSpec(c).getName());
            for (Map.Entry<DataCell, Integer> e : m_nominalValues[c].entrySet()) {
                NodeSettingsWO nomSett = subSett.addNodeSettings(e.getKey().toString());
                nomSett.addDataCell("key", e.getKey());
                nomSett.addInt("value", e.getValue());
            }
        }
    }
}
Also used : MutableInteger(org.knime.core.util.MutableInteger) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 97 with NodeSettingsWO

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

the class DataContainer method writeToStream.

/**
 * Writes a given DataTable permanently to an output stream. This includes also all table spec information, such as
 * color, size, and shape properties.
 *
 * <p>
 * The content is saved by instantiating a {@link ZipOutputStream} on the argument stream, saving the necessary
 * information in respective zip entries. The stream is not closed by this method.
 *
 * @param table The table to write.
 * @param out The stream to save to. It does not have to be buffered.
 * @param exec For progress info.
 * @throws IOException If writing fails.
 * @throws CanceledExecutionException If canceled.
 * @see #readFromStream(InputStream)
 */
public static void writeToStream(final DataTable table, final OutputStream out, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    Buffer buf;
    ExecutionMonitor e = exec;
    boolean canUseBuffer = table instanceof ContainerTable;
    if (canUseBuffer) {
        Buffer b = ((ContainerTable) table).getBuffer();
        if (b.containsBlobCells() && b.getBufferID() != -1) {
            canUseBuffer = false;
        }
    }
    if (canUseBuffer) {
        buf = ((ContainerTable) table).getBuffer();
    } else {
        exec.setMessage("Archiving table");
        e = exec.createSubProgress(0.8);
        buf = new Buffer(table.getDataTableSpec(), 0, -1, new HashMap<Integer, ContainerTable>(), new HashMap<Integer, ContainerTable>(), NotInWorkflowWriteFileStoreHandler.create());
        int rowCount = 0;
        for (DataRow row : table) {
            rowCount++;
            e.setMessage("Writing row #" + rowCount + " (\"" + row.getKey() + "\")");
            e.checkCanceled();
            buf.addRow(row, false, false);
        }
        buf.close(table.getDataTableSpec());
        exec.setMessage("Closing zip file");
        e = exec.createSubProgress(0.2);
    }
    final boolean originalOutputIsBuffered = ((out instanceof BufferedOutputStream) || (out instanceof ByteArrayOutputStream));
    OutputStream os = originalOutputIsBuffered ? out : new BufferedOutputStream(out);
    ZipOutputStream zipOut = new ZipOutputStream(os);
    // (part of) bug fix #1141: spec must be put as first entry in order
    // for the table reader to peek it
    zipOut.putNextEntry(new ZipEntry(ZIP_ENTRY_SPEC));
    NodeSettings settings = new NodeSettings("Table Spec");
    NodeSettingsWO specSettings = settings.addNodeSettings(CFG_TABLESPEC);
    buf.getTableSpec().save(specSettings);
    settings.saveToXML(new NonClosableOutputStream.Zip(zipOut));
    buf.addToZipFile(zipOut, e);
    zipOut.finish();
    if (!originalOutputIsBuffered) {
        os.flush();
    }
}
Also used : HashMap(java.util.HashMap) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NonClosableOutputStream(org.knime.core.data.util.NonClosableOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataRow(org.knime.core.data.DataRow) NodeSettings(org.knime.core.node.NodeSettings) ZipOutputStream(java.util.zip.ZipOutputStream) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) BufferedOutputStream(java.io.BufferedOutputStream) NonClosableOutputStream(org.knime.core.data.util.NonClosableOutputStream)

Example 98 with NodeSettingsWO

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

the class Buffer method writeMetaToFile.

/**
 * Writes internals to the an output stream (using the xml scheme from NodeSettings).
 *
 * @param out To write to.
 * @throws IOException If that fails.
 */
private void writeMetaToFile(final OutputStream out) throws IOException {
    NodeSettings settings = new NodeSettings("Table Meta Information");
    NodeSettingsWO subSettings = settings.addNodeSettings(CFG_INTERNAL_META);
    subSettings.addString(CFG_VERSION, getVersion());
    if (size() < Integer.MAX_VALUE) {
        subSettings.addInt(CFG_SIZE, (int) size());
    } else {
        subSettings.addLong(CFG_SIZE_L, size());
    }
    subSettings.addBoolean(CFG_CONTAINS_BLOBS, m_containsBlobs);
    // added between version 8 and 9 - no increment of version number
    String fileStoresUUID = null;
    if (m_fileStoreHandler instanceof NotInWorkflowWriteFileStoreHandler) {
        NotInWorkflowWriteFileStoreHandler notInWorkflowFSH = (NotInWorkflowWriteFileStoreHandler) m_fileStoreHandler;
        if (notInWorkflowFSH.hasCopiedFileStores()) {
            fileStoresUUID = notInWorkflowFSH.getStoreUUID().toString();
        }
    }
    subSettings.addString(CFG_FILESTORES_UUID, fileStoresUUID);
    subSettings.addBoolean(CFG_IS_IN_MEMORY, !usesOutFile());
    subSettings.addInt(CFG_BUFFER_ID, m_bufferID);
    subSettings.addString(CFG_TABLE_FORMAT, m_outputFormat.getClass().getName());
    NodeSettingsWO formatSettings = subSettings.addNodeSettings(CFG_TABLE_FORMAT_CONFIG);
    m_outputWriter.writeMetaInfoAfterWrite(formatSettings);
    settings.saveToXML(out);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) NodeSettingsWO(org.knime.core.node.NodeSettingsWO)

Example 99 with NodeSettingsWO

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

the class TableSpecReplacerTable method saveToFile.

/**
 * {@inheritDoc}
 */
@Override
public void saveToFile(final File f, final NodeSettingsWO s, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    NodeSettingsWO subSettings = s.addNodeSettings(CFG_INTERNAL_META);
    subSettings.addInt(CFG_REFERENCE_ID, m_reference.getBufferedTableId());
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO)

Example 100 with NodeSettingsWO

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

the class WrappedTable method saveToFile.

/**
 * {@inheritDoc}
 */
@Override
public void saveToFile(final File f, final NodeSettingsWO s, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    NodeSettingsWO subSettings = s.addNodeSettings(CFG_INTERNAL_META);
    subSettings.addInt(CFG_REFERENCE_ID, m_table.getBufferedTableId());
}
Also used : NodeSettingsWO(org.knime.core.node.NodeSettingsWO)

Aggregations

NodeSettingsWO (org.knime.core.node.NodeSettingsWO)111 NodeSettings (org.knime.core.node.NodeSettings)16 Map (java.util.Map)11 File (java.io.File)9 FileOutputStream (java.io.FileOutputStream)9 LinkedHashMap (java.util.LinkedHashMap)9 HashMap (java.util.HashMap)8 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)8 RowKey (org.knime.core.data.RowKey)6 DataCell (org.knime.core.data.DataCell)5 BufferedOutputStream (java.io.BufferedOutputStream)4 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)4 HashSet (java.util.HashSet)3 GZIPOutputStream (java.util.zip.GZIPOutputStream)3 DataRow (org.knime.core.data.DataRow)3 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)3 AbstractQuickFormConfiguration (org.knime.core.quickform.AbstractQuickFormConfiguration)3 AbstractQuickFormValueInConfiguration (org.knime.core.quickform.AbstractQuickFormValueInConfiguration)3 QuickFormInputNode (org.knime.core.quickform.in.QuickFormInputNode)3 MutableInteger (org.knime.core.util.MutableInteger)3