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