Search in sources :

Example 6 with IFileStoreHandler

use of org.knime.core.data.filestore.internal.IFileStoreHandler in project knime-core by knime.

the class Buffer method readMetaFromFile.

/**
 * Reads meta information, that is row count, version, byte assignments.
 *
 * @param metaIn To read from.
 * @throws IOException If reading fails.
 * @throws ClassNotFoundException If any of the classes can't be loaded.
 * @throws InvalidSettingsException If the internal structure is broken.
 */
private void readMetaFromFile(final InputStream metaIn, final File fileStoreDir) throws IOException, InvalidSettingsException {
    try (InputStream inStream = new BufferedInputStream(metaIn)) {
        NodeSettingsRO settings = NodeSettings.loadFromXML(inStream);
        NodeSettingsRO subSettings = settings.getNodeSettings(CFG_INTERNAL_META);
        String version = subSettings.getString(CFG_VERSION);
        m_version = validateVersion(version);
        if (subSettings.containsKey(CFG_SIZE_L)) {
            m_size = subSettings.getLong(CFG_SIZE_L);
        } else {
            m_size = subSettings.getInt(CFG_SIZE);
        }
        if (m_size < 0) {
            throw new IOException("Table size must not be < 0: " + m_size);
        }
        // added sometime between format 8 and 9
        m_containsBlobs = false;
        if (m_version >= 4) {
            // no blobs in version 1.1.x
            m_containsBlobs = subSettings.getBoolean(CFG_CONTAINS_BLOBS);
            int bufferID = subSettings.getInt(CFG_BUFFER_ID);
            // bufferID of -1. 1.0.0 contain no blobs, so that's ok.
            if (m_containsBlobs && bufferID != m_bufferID) {
                LOGGER.error("Table's buffer id is different from what has" + " been passed in constructor (" + bufferID + " vs. " + m_bufferID + "), unpredictable errors may occur");
            }
        }
        IFileStoreHandler fileStoreHandler = new EmptyFileStoreHandler(m_fileStoreHandlerRepository);
        if (m_version >= 8) {
            // file stores added between version 8 and 9
            String fileStoresUUIDS = subSettings.getString(CFG_FILESTORES_UUID, null);
            UUID fileStoresUUID = null;
            if (fileStoresUUIDS != null) {
                try {
                    fileStoresUUID = UUID.fromString(fileStoresUUIDS);
                } catch (IllegalArgumentException iae) {
                    throw new InvalidSettingsException("Can't parse UUID " + fileStoresUUIDS, iae);
                }
            }
            if (fileStoresUUID != null) {
                NotInWorkflowWriteFileStoreHandler notInWorkflowFSH = new NotInWorkflowWriteFileStoreHandler(fileStoresUUID, m_fileStoreHandlerRepository);
                notInWorkflowFSH.setBaseDir(fileStoreDir);
                fileStoreHandler = notInWorkflowFSH;
            }
        }
        m_fileStoreHandler = fileStoreHandler;
        if (m_version >= 8) {
            // with buffer version 8 (> 2.0)
            if (subSettings.getBoolean(CFG_IS_IN_MEMORY)) {
                restoreIntoMemory();
            }
        }
        String outputFormat = subSettings.getString(CFG_TABLE_FORMAT, DefaultTableStoreFormat.class.getName());
        m_outputFormat = TableStoreFormatRegistry.getInstance().getTableStoreFormat(outputFormat).orElseThrow(() -> new InvalidSettingsException(String.format("Invalid table format '%s' - unable to restore table.", outputFormat)));
        NodeSettingsRO outputFormatSettings = m_version >= 10 ? subSettings.getNodeSettings(CFG_TABLE_FORMAT_CONFIG) : subSettings;
        initOutputReader(outputFormatSettings, m_version);
    }
}
Also used : NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EmptyFileStoreHandler(org.knime.core.data.filestore.internal.EmptyFileStoreHandler) IOException(java.io.IOException) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IFileStoreHandler(org.knime.core.data.filestore.internal.IFileStoreHandler) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) UUID(java.util.UUID)

Aggregations

IFileStoreHandler (org.knime.core.data.filestore.internal.IFileStoreHandler)6 ReferencedFile (org.knime.core.internal.ReferencedFile)3 File (java.io.File)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 EmptyFileStoreHandler (org.knime.core.data.filestore.internal.EmptyFileStoreHandler)2 WriteFileStoreHandler (org.knime.core.data.filestore.internal.WriteFileStoreHandler)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1