Search in sources :

Example 6 with FileStore

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

the class LoopStartWritableFileStoreHandler method createFileStore.

/**
 * {@inheritDoc}
 */
@Override
public synchronized FileStore createFileStore(final String name) throws IOException {
    final FileStore fs = createFileStoreInLoopBody(name);
    super.addToDuplicateChecker(name);
    return fs;
}
Also used : FileStore(org.knime.core.data.filestore.FileStore)

Example 7 with FileStore

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

the class WriteFileStoreHandler method createFileStoreInternal.

FileStore createFileStoreInternal(final String name, final byte[] nestedLoopPath, final int iterationIndex) throws IOException {
    assert Thread.holdsLock(this);
    CheckUtils.checkArgumentNotNull(name, "Argument must not be null.");
    if (name.startsWith(".")) {
        throw new IOException("Name must not start with a dot: \"" + name + "\"");
    }
    if (name.contains("/") || name.contains("\\")) {
        throw new IOException("Invalid file name, must not contain (back) slash: \"" + name + "\"");
    }
    FileStoreKey key = new FileStoreKey(m_storeUUID, m_nextIndex, nestedLoopPath, iterationIndex, name);
    ensureInitBaseDirectory();
    if (m_nextIndex > MAX_NR_FILES) {
        throw new IOException("Maximum number of files stores reached: " + MAX_NR_FILES);
    }
    getParentDir(m_nextIndex, true);
    m_nextIndex++;
    FileStore fs = FileStoreUtil.createFileStore(this, key);
    return fs;
}
Also used : FileStore(org.knime.core.data.filestore.FileStore) FileStoreKey(org.knime.core.data.filestore.FileStoreKey) IOException(java.io.IOException)

Example 8 with FileStore

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

the class BinaryObjectCellFactory method create.

/**
 * Creates cell given by reading from an input stream. The stream will be closed by this method.
 * @param input To read from.
 * @return A cell with a copy of the byte content.
 * @throws IOException If that fails (stream not readable, file store not writable, close problems, ...)
 * @throws NullPointerException If argument is null.
 */
@DataCellFactoryMethod(name = "InputStream")
public DataCell create(final InputStream input) throws IOException {
    String uniqueFileName = "knime-binary-copy-";
    String suffix = ".bin";
    MessageDigest md5MessageDigest = newMD5Digest();
    DeferredFileOutputStream outStream = new DeferredFileOutputStream(MEMORY_LIMIT, uniqueFileName, suffix, TMP_DIR_FOLDER);
    DigestInputStream digestInputStream = new DigestInputStream(input, md5MessageDigest);
    IOUtils.copy(digestInputStream, outStream);
    digestInputStream.close();
    outStream.close();
    byte[] md5sum = md5MessageDigest.digest();
    if (outStream.isInMemory()) {
        return new BinaryObjectDataCell(outStream.getData(), md5sum);
    } else {
        FileStore fs;
        synchronized (this) {
            String name = "binaryObject-" + m_fileNameIndex++;
            fs = m_fileStoreFactory.createFileStore(name);
        }
        File f = outStream.getFile();
        assert f.exists() : "File " + f.getAbsolutePath() + " not created by file output stream";
        FileUtils.moveFile(f, fs.getFile());
        return new BinaryObjectFileStoreDataCell(fs, md5sum);
    }
}
Also used : FileStore(org.knime.core.data.filestore.FileStore) DigestInputStream(java.security.DigestInputStream) MessageDigest(java.security.MessageDigest) DeferredFileOutputStream(org.apache.commons.io.output.DeferredFileOutputStream) File(java.io.File) DataCellFactoryMethod(org.knime.core.data.convert.DataCellFactoryMethod)

Example 9 with FileStore

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

the class Buffer method mustBeFlushedPriorSave.

private boolean mustBeFlushedPriorSave(final DataCell cell) {
    if (cell instanceof FileStoreCell) {
        FileStore fileStore = FileStoreUtil.getFileStore((FileStoreCell) cell);
        return ((IWriteFileStoreHandler) m_fileStoreHandler).mustBeFlushedPriorSave(fileStore);
    } else if (cell instanceof CollectionDataValue) {
        for (DataCell c : (CollectionDataValue) cell) {
            if (mustBeFlushedPriorSave(c)) {
                return true;
            }
        }
    } else if (cell instanceof BlobWrapperDataCell) {
        final BlobWrapperDataCell blobWrapperCell = (BlobWrapperDataCell) cell;
        Class<? extends BlobDataCell> blobClass = blobWrapperCell.getBlobClass();
        if (CollectionDataValue.class.isAssignableFrom(blobClass)) {
            return mustBeFlushedPriorSave(blobWrapperCell.getCell());
        }
    }
    return false;
}
Also used : FileStore(org.knime.core.data.filestore.FileStore) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) DataCell(org.knime.core.data.DataCell) FileStoreCell(org.knime.core.data.filestore.FileStoreCell) CollectionDataValue(org.knime.core.data.collection.CollectionDataValue)

Example 10 with FileStore

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

the class AbstractTableStoreWriter method getFileStoreKeyAndFlush.

/**
 * @param cell
 * @return
 * @throws IOException
 */
public FileStoreKey getFileStoreKeyAndFlush(final DataCell cell) throws IOException {
    FileStoreKey fileStoreKey = null;
    if (cell instanceof FileStoreCell) {
        final FileStoreCell fsCell = (FileStoreCell) cell;
        FileStore fileStore = FileStoreUtil.getFileStore(fsCell);
        // TODO is the 'else' case realistic?
        if (getFileStoreHandler() instanceof IWriteFileStoreHandler) {
            fileStoreKey = getFileStoreHandler().translateToLocal(fileStore, fsCell);
        } else {
            // handler is not an IWriteFileStoreHandler but the buffer still contains file stores:
            // the flow is part of a workflow and all file stores were already properly handled
            // (this buffer is restored from disc - and then a memory alert forces the data back onto disc)
            fileStoreKey = FileStoreUtil.getFileStoreKey(fileStore);
        }
        FileStoreUtil.invokeFlush(fsCell);
    }
    return fileStoreKey;
}
Also used : FileStore(org.knime.core.data.filestore.FileStore) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) FileStoreKey(org.knime.core.data.filestore.FileStoreKey) FileStoreCell(org.knime.core.data.filestore.FileStoreCell)

Aggregations

FileStore (org.knime.core.data.filestore.FileStore)12 FileStoreKey (org.knime.core.data.filestore.FileStoreKey)4 File (java.io.File)3 IOException (java.io.IOException)2 FileStoreCell (org.knime.core.data.filestore.FileStoreCell)2 IWriteFileStoreHandler (org.knime.core.data.filestore.internal.IWriteFileStoreHandler)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 DigestInputStream (java.security.DigestInputStream)1 MessageDigest (java.security.MessageDigest)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 DeferredFileOutputStream (org.apache.commons.io.output.DeferredFileOutputStream)1 DataCell (org.knime.core.data.DataCell)1 CollectionDataValue (org.knime.core.data.collection.CollectionDataValue)1 DataCellFactoryMethod (org.knime.core.data.convert.DataCellFactoryMethod)1 FileStorePortObject (org.knime.core.data.filestore.FileStorePortObject)1 NotInWorkflowWriteFileStoreHandler (org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler)1