Search in sources :

Example 1 with ModelContent

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

the class DecTreePredictorNodeModel method saveInternals.

/**
 * Save internals.
 *
 * @param nodeInternDir The intern node directory to save table to.
 * @param exec Used to report progress or cancel saving.
 * @throws IOException Always, since this method has not been implemented
 *             yet.
 * @see org.knime.core.node.NodeModel
 *      #saveInternals(java.io.File,ExecutionMonitor)
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
    // write the tree as pred params
    ModelContent model = new ModelContent(INTERNALS_FILE_NAME);
    m_decTree.saveToPredictorParams(model, true);
    File internalsFile = new File(nodeInternDir, INTERNALS_FILE_NAME);
    BufferedOutputStream out2 = new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(internalsFile)));
    model.saveToXML(out2);
    out2.close();
}
Also used : GZIPOutputStream(java.util.zip.GZIPOutputStream) ModelContent(org.knime.core.node.ModelContent) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with ModelContent

use of org.knime.core.node.ModelContent 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 ModelContent

use of org.knime.core.node.ModelContent 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 ModelContent

use of org.knime.core.node.ModelContent 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 ModelContent

use of org.knime.core.node.ModelContent 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

ModelContent (org.knime.core.node.ModelContent)29 File (java.io.File)15 FileOutputStream (java.io.FileOutputStream)15 BufferedOutputStream (java.io.BufferedOutputStream)12 GZIPOutputStream (java.util.zip.GZIPOutputStream)11 ModelContentWO (org.knime.core.node.ModelContentWO)7 JComponent (javax.swing.JComponent)6 ModelContentOutPortView (org.knime.core.node.workflow.ModelContentOutPortView)6 DataTableSpec (org.knime.core.data.DataTableSpec)3 ZipEntry (java.util.zip.ZipEntry)2 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)2 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 LinkedHashSet (java.util.LinkedHashSet)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)1