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);
}
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);
}
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))));
}
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))));
}
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();
}
}
Aggregations