use of org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler 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();
}
}
use of org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler in project knime-core by knime.
the class FileStoreFactory method createNotInWorkflowFileStoreFactory.
/**
* Creates a factory whose generated file stores are not part of the workflow. It's used in isolated
* data tables (such as used in views).
* @return Such a new factory.
* @since 2.7
*/
public static final FileStoreFactory createNotInWorkflowFileStoreFactory() {
NotInWorkflowWriteFileStoreHandler fsh = new NotInWorkflowWriteFileStoreHandler(UUID.randomUUID());
fsh.open();
return new NotInWorkflowFileStoreFactory(fsh);
}
use of org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler 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);
}
use of org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler in project knime-core by knime.
the class FileStoreFactory method createNotInWorkflowFileStoreFactory.
/**
* Creates a factory whose generated file stores are not part of the workflow. It's used in isolated
* data tables (such as used in views).
* @param prefix the file name prefix to use when creating the {@link FileStore}
* @return Such a new factory.
* @since 4.1
*/
public static final FileStoreFactory createNotInWorkflowFileStoreFactory(final String prefix) {
NotInWorkflowWriteFileStoreHandler fsh = new NotInWorkflowWriteFileStoreHandler(UUID.randomUUID());
fsh.open();
return new NotInWorkflowFileStoreFactory(fsh, prefix);
}
use of org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler 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 Supplier<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, m_lifecycle.shallLoadBackIntoMemory());
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_formatSettings.copyTo(formatSettings);
if (m_outputWriter instanceof DefaultTableStoreWriter) {
// AP-8954 -- for standard KNIME tables write the meta information into the root so that 3.5 and before
// can load it;
// these settings are no longer read in newer versions of KNIME (3.6+) -- attempt of forward compatibility
m_formatSettings.copyTo(subSettings);
}
settings.saveToXML(out.get());
}
Aggregations