use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.
the class ListMimeFileImporterNodeModel method execute.
@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception {
String[] filenames = m_filenames.getStringArrayValue();
List<URIContent> uris = new ArrayList<URIContent>();
for (String filename : filenames) {
File in = new File(convertToURL(filename).toURI());
if (!in.canRead()) {
throw new Exception("Cannot read from input file: " + in.getAbsolutePath());
}
uris.add(new URIContent(in.toURI(), (m_file_extension.isActive() ? m_file_extension.getStringValue() : MIMETypeHelper.getMIMEtypeExtension(filename))));
}
return new PortObject[] { new URIPortObject(uris) };
}
use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.
the class ManglerNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
// translate portobject to table
BufferedDataTable table = (BufferedDataTable) inData[0];
// create a file where we can write to
FileStoreURIPortObject fsupo;
fsupo = new FileStoreURIPortObject(exec.createFileStore("ManglerNodeModel"));
// File file = fileStash.getFile(demangler.getMIMEType(), "mime");
File file = fsupo.registerFile("mangled_file." + demangler.getMIMEType());
// translate the filename to a URIContent
URIContent outputURI = new URIContent(file.toURI(), demangler.getMIMEType());
// write file
demangler.mangle(table, outputURI.getURI());
// create list
List<URIContent> uriList = new ArrayList<URIContent>();
uriList.add(outputURI);
return new FileStoreURIPortObject[] { fsupo };
}
use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.
the class OutputFileNodeModel method execute.
@Override
protected PortObject[] execute(PortObject[] inObjects, ExecutionContext exec) throws Exception {
IURIPortObject obj = (IURIPortObject) inObjects[0];
List<URIContent> uris = obj.getURIContents();
if (uris.size() == 0) {
throw new Exception("There were no URIs in the supplied IURIPortObject at port 0");
}
String filename = m_filename.getStringValue();
File in = new File(uris.get(0).getURI());
File out = new File(filename);
FileUtils.copyFile(in, out);
data = Helper.readFileSummary(in, 50);
return new PortObject[] {};
}
use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.
the class MimeDirectoryImporterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
// Create connection monitor
final ConnectionMonitor<? extends Connection> monitor = new ConnectionMonitor<>();
// Create output URI container
final List<URIContent> uris = new ArrayList<URIContent>();
try {
URI directoryUri;
if (m_connectionInformation != null) {
exec.setProgress("Connecting to " + m_connectionInformation.toURI());
// Generate URI to the directory
directoryUri = new URI(m_connectionInformation.toURI().toString() + NodeUtils.encodePath(m_configuration.getDirectory()));
} else {
// Create local URI
directoryUri = new File(m_configuration.getDirectory()).toURI();
}
// Create remote file for directory selection
final RemoteFile<? extends Connection> file = RemoteFileFactory.createRemoteFile(directoryUri, m_connectionInformation, monitor);
// List the selected directory
exec.setProgress("Retrieving list of files");
listDirectory(file, uris, true, exec, new MutableInteger(0), new MutableInteger(0));
} finally {
// Close connections
monitor.closeAll();
}
return new PortObject[] { new URIPortObject(uris) };
}
use of org.knime.core.data.uri.URIContent in project GenericKnimeNodes by genericworkflownodes.
the class MimeDirectoryImporterNodeModel method listDirectory.
/**
* List a directory.
*
* Writes the location of all files in a directory into the container. Files
* will be listed recursively if the option is selected.
*
* @param file The file or directory to be listed
* @param uris List of URIContents to write the reference of the files into
* @param root If this directory is the root directory
* @param exec Execution context to check if the execution has been canceled
* @throws Exception If remote file operation did not succeed
*/
private void listDirectory(final RemoteFile<? extends Connection> file, final List<URIContent> uris, final boolean root, final ExecutionContext exec, final MutableInteger processedEntries, final MutableInteger maxEntries) throws Exception {
// Check if the user canceled
exec.checkCanceled();
if (!root) {
final URI fileUri = file.getURI();
// URI to the file
final String extension = FilenameUtils.getExtension(fileUri.getPath());
final URIContent content = new URIContent(fileUri, extension);
// Add file information to the output
if (!file.isDirectory()) {
uris.add(content);
}
}
// If the source is a directory list inner files
if (file.isDirectory()) {
if (root || m_configuration.getRecursive()) {
final RemoteFile<? extends Connection>[] files = file.listFiles();
Arrays.sort(files);
final RemoteFile<? extends Connection>[] filteredFiles = filterFiles(files);
maxEntries.setValue(maxEntries.intValue() + filteredFiles.length);
exec.setMessage("Scanning " + file.getFullName());
for (final RemoteFile<? extends Connection> file2 : filteredFiles) {
listDirectory(file2, uris, false, exec, processedEntries, maxEntries);
processedEntries.inc();
exec.setProgress(processedEntries.intValue() / maxEntries.doubleValue());
}
}
}
}
Aggregations