Search in sources :

Example 1 with ModelContentWO

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

the class NaiveBayesPortObjectSpec method save.

/**
 * {@inheritDoc}
 */
@Override
protected void save(final ModelContentWO model) {
    final Config specModel = model.addConfig(CNFG_SPEC);
    m_tableSpec.save(specModel);
    final ModelContentWO classColModel = model.addModelContent(CNFG_CLASS_COL);
    m_classColumn.save(classColModel);
}
Also used : Config(org.knime.core.node.config.Config) ModelContentWO(org.knime.core.node.ModelContentWO)

Example 2 with ModelContentWO

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

the class LinRegLearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    ModelContent content = new ModelContent(CFG_SETTINGS);
    content.addInt(CFG_NR_ROWS, m_nrRows);
    content.addInt(CFG_NR_ROWS_SKIPPED, m_nrRowsSkipped);
    content.addDouble(CFG_ERROR, m_error);
    ModelContentWO specContent = content.addModelContent(CFG_SPEC);
    m_params.getSpec().save(specContent);
    specContent.addStringArray(CFG_USED_COLUMNS, m_actualUsedColumns);
    ModelContentWO parContent = content.addModelContent(CFG_PARAMS);
    m_params.save(parContent);
    File outFile = new File(internDir, FILE_SAVE);
    content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
    File dataFile = new File(internDir, FILE_DATA);
    DataContainer.writeToZip(m_rowContainer, dataFile, exec);
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ModelContent(org.knime.core.node.ModelContent) ModelContentWO(org.knime.core.node.ModelContentWO) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with ModelContentWO

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

the class LogRegLearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    ModelContent content = new ModelContent(CFG_SETTINGS);
    ModelContentWO specContent = content.addModelContent(CFG_SPEC);
    m_content.getSpec().getDataTableSpec().save(specContent);
    ModelContentWO parContent = content.addModelContent(CFG_LOGREG_CONTENT);
    m_content.save(parContent);
    File outFile = new File(internDir, FILE_SAVE);
    content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ModelContent(org.knime.core.node.ModelContent) ModelContentWO(org.knime.core.node.ModelContentWO) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 4 with ModelContentWO

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

the class LogRegLearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    ModelContent content = new ModelContent(CFG_SETTINGS);
    ModelContentWO specContent = content.addModelContent(CFG_SPEC);
    m_content.getSpec().getDataTableSpec().save(specContent);
    ModelContentWO parContent = content.addModelContent(CFG_LOGREG_CONTENT);
    m_content.save(parContent);
    File outFile = new File(internDir, FILE_SAVE);
    content.saveToXML(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(outFile))));
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ModelContent(org.knime.core.node.ModelContent) ModelContentWO(org.knime.core.node.ModelContentWO) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 5 with ModelContentWO

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

the class PortUtil method writeObjectToStream.

/**
 * Write the given port object into the given output stream. The output stream does not need to be buffered and is
 * not closed after calling this method.
 *
 * @param po any port object
 * @param output any output stream, does not need to be buffered
 * @param exec execution context for reporting progress and checking for cancelation
 * @throws IOException if an I/O error occurs while serializing the port object
 * @throws CanceledExecutionException if the user canceled the operation
 */
public static void writeObjectToStream(final PortObject po, final OutputStream output, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    final boolean originalOutputIsBuffered = ((output instanceof BufferedOutputStream) || (output instanceof ByteArrayOutputStream));
    OutputStream os = originalOutputIsBuffered ? output : new BufferedOutputStream(output);
    final ZipOutputStream zipOut = new ZipOutputStream(os);
    PortObjectSpec spec = po.getSpec();
    zipOut.putNextEntry(new ZipEntry("content.xml"));
    ModelContent toc = new ModelContent("content");
    toc.addInt("version", 1);
    toc.addString("port_spec_class", spec.getClass().getName());
    toc.addString("port_object_class", po.getClass().getName());
    NotInWorkflowWriteFileStoreHandler fileStoreHandler = null;
    if (po instanceof FileStorePortObject) {
        fileStoreHandler = NotInWorkflowWriteFileStoreHandler.create();
        ModelContentWO fileStoreModelContent = toc.addModelContent("filestores");
        fileStoreModelContent.addString("handlerUUID", fileStoreHandler.getStoreUUID().toString());
        final FileStorePortObject fileStorePO = (FileStorePortObject) po;
        FileStoreUtil.invokeFlush(fileStorePO);
        List<FileStore> fileStores = FileStoreUtil.getFileStores(fileStorePO);
        ModelContentWO fileStoreKeysModel = fileStoreModelContent.addModelContent("port_file_store_keys");
        for (int i = 0; i < fileStores.size(); i++) {
            FileStoreKey key = fileStoreHandler.translateToLocal(fileStores.get(i), fileStorePO);
            key.save(fileStoreKeysModel.addModelContent("filestore_key_" + i));
        }
    }
    toc.saveToXML(new NonClosableOutputStream.Zip(zipOut));
    zipOut.putNextEntry(new ZipEntry("objectSpec.file"));
    try (PortObjectSpecZipOutputStream specOut = getPortObjectSpecZipOutputStream(new NonClosableOutputStream.Zip(zipOut))) {
        PortObjectSpecSerializer specSer = PortTypeRegistry.getInstance().getSpecSerializer(spec.getClass()).get();
        specSer.savePortObjectSpec(spec, specOut);
    }
    // 'close' will propagate as closeEntry
    zipOut.putNextEntry(new ZipEntry("object.file"));
    try (PortObjectZipOutputStream objOut = getPortObjectZipOutputStream(new NonClosableOutputStream.Zip(zipOut))) {
        PortObjectSerializer objSer = PortTypeRegistry.getInstance().getObjectSerializer(po.getClass()).get();
        objSer.savePortObject(po, objOut, exec);
    }
    if (fileStoreHandler != null && fileStoreHandler.hasCopiedFileStores()) {
        zipOut.putNextEntry(new ZipEntry("filestores/"));
        zipOut.closeEntry();
        File baseDir = fileStoreHandler.getBaseDir();
        FileUtil.zipDir(zipOut, Arrays.asList(baseDir.listFiles()), "filestores/", FileUtil.ZIP_INCLUDEALL_FILTER, exec.createSubProgress(0.5));
    }
    zipOut.finish();
    if (!originalOutputIsBuffered) {
        os.flush();
    }
}
Also used : NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) ModelContent(org.knime.core.node.ModelContent) ModelContentWO(org.knime.core.node.ModelContentWO) 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) FileStorePortObject(org.knime.core.data.filestore.FileStorePortObject) FileStore(org.knime.core.data.filestore.FileStore) FileStoreKey(org.knime.core.data.filestore.FileStoreKey) ZipOutputStream(java.util.zip.ZipOutputStream) PortObjectSpecSerializer(org.knime.core.node.port.PortObjectSpec.PortObjectSpecSerializer) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File) NonClosableOutputStream(org.knime.core.data.util.NonClosableOutputStream) PortObjectSerializer(org.knime.core.node.port.PortObject.PortObjectSerializer)

Aggregations

ModelContentWO (org.knime.core.node.ModelContentWO)23 BufferedOutputStream (java.io.BufferedOutputStream)7 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)7 ModelContent (org.knime.core.node.ModelContent)7 GZIPOutputStream (java.util.zip.GZIPOutputStream)6 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 GroupKey (org.knime.base.node.preproc.groupby.GroupKey)2 DataCell (org.knime.core.data.DataCell)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStream (java.io.OutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 RowKey (org.knime.core.data.RowKey)1 FileStore (org.knime.core.data.filestore.FileStore)1 FileStoreKey (org.knime.core.data.filestore.FileStoreKey)1