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 PortUtil method readObjectFromStream.
public static PortObject readObjectFromStream(final InputStream input, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
try (ZipInputStream in = new ZipInputStream(new BufferedInputStream(input))) {
ZipEntry entry = in.getNextEntry();
// Check that the given input stream really specifies a port object
if (entry == null) {
throw new IOException("File does not specify a valid port object model");
}
if (!"content.xml".equals(entry.getName())) {
throw new IOException("Invalid stream, expected zip entry \"content.xml\", got \"" + entry.getName() + "\"");
}
ModelContentRO toc = ModelContent.loadFromXML(new NonClosableInputStream.Zip(in));
String specClassName = toc.getString("port_spec_class");
String objClassName = toc.getString("port_object_class");
// reads "objectSpec.file"
PortObjectSpec spec = readObjectSpec(specClassName, in);
entry = in.getNextEntry();
if (!"object.file".equals(entry.getName())) {
throw new IOException("Invalid stream, expected zip entry \"object.file\", got \"" + entry.getName() + "\"");
}
Class<? extends PortObject> cl = PortTypeRegistry.getInstance().getObjectClass(objClassName).orElseThrow(() -> new IOException("Can't load class \"" + specClassName + "\""));
PortObject portObject;
try (PortObjectZipInputStream objIn = getPortObjectZipInputStream(new NonClosableInputStream.Zip(in))) {
PortObjectSerializer<?> objSer = PortTypeRegistry.getInstance().getObjectSerializer(cl.asSubclass(PortObject.class)).get();
portObject = objSer.loadPortObject(objIn, spec, exec);
}
if (portObject instanceof FileStorePortObject) {
ModelContentRO fileStoreModelContent = toc.getModelContent("filestores");
UUID iFileStoreHandlerUUID = UUID.fromString(fileStoreModelContent.getString("handlerUUID"));
ModelContentRO fileStoreKeysModel = fileStoreModelContent.getModelContent("port_file_store_keys");
List<FileStoreKey> fileStoreKeys = new ArrayList<>();
for (String key : fileStoreKeysModel.keySet()) {
fileStoreKeys.add(FileStoreKey.load(fileStoreKeysModel.getModelContent(key)));
}
NotInWorkflowWriteFileStoreHandler notInWorkflowFSHandler = new NotInWorkflowWriteFileStoreHandler(iFileStoreHandlerUUID);
entry = in.getNextEntry();
if (entry != null && "filestores/".equals(entry.getName())) {
File fileStoreDir = FileUtil.createTempDir("knime_fs_" + cl.getSimpleName() + "-");
FileUtil.unzip(in, fileStoreDir, 1);
notInWorkflowFSHandler.setBaseDir(fileStoreDir);
}
FileStoreUtil.retrieveFileStoreHandlerFrom((FileStorePortObject) portObject, fileStoreKeys, notInWorkflowFSHandler.getDataRepository());
}
return portObject;
} catch (InvalidSettingsException ex) {
throw new IOException("Unable to parse content.xml in port object file", ex);
}
}
Aggregations