use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.
the class VFSFileProvider method writeFile.
/**
* @param inputStream
* @param destDir
* @param path
* @param overwrite
* @return
* @throws FileException
*/
@Override
public VFSFile writeFile(InputStream inputStream, VFSFile destDir, String path, boolean overwrite) throws FileException {
FileObject fileObject = null;
try {
fileObject = KettleVFS.getFileObject(path, new Variables(), VFSHelper.getOpts(destDir.getPath(), destDir.getConnection()));
} catch (KettleException ke) {
throw new FileException();
}
if (fileObject != null) {
try (OutputStream outputStream = fileObject.getContent().getOutputStream()) {
IOUtils.copy(inputStream, outputStream);
outputStream.flush();
return VFSFile.create(destDir.getPath(), fileObject, destDir.getConnection(), destDir.getDomain());
} catch (IOException e) {
return null;
}
}
return null;
}
use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.
the class VFSFileProvider method getFile.
@Override
public VFSFile getFile(VFSFile file) {
try {
FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
if (!fileObject.exists()) {
return null;
}
String parent = null;
if (fileObject.getParent() != null && fileObject.getParent().getName() != null) {
parent = fileObject.getParent().getName().getURI();
} else {
parent = fileObject.getURL().getProtocol() + "://";
}
if (fileObject.getType().equals(FileType.FOLDER)) {
return VFSDirectory.create(parent, fileObject, null, file.getDomain());
} else {
return VFSFile.create(parent, fileObject, null, file.getDomain());
}
} catch (KettleFileException | FileSystemException e) {
// File does not exist
}
return null;
}
use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.
the class VFSFileProvider method doMove.
/**
* @param file
* @param newPath
* @param overwrite
* @return
*/
private VFSFile doMove(VFSFile file, String newPath, boolean overwrite) {
try {
FileObject fileObject = KettleVFS.getFileObject(file.getPath(), new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
FileObject renameObject = KettleVFS.getFileObject(newPath, new Variables(), VFSHelper.getOpts(file.getPath(), file.getConnection()));
if (overwrite && renameObject.exists()) {
renameObject.delete();
}
fileObject.moveTo(renameObject);
if (file instanceof VFSDirectory) {
return VFSDirectory.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
} else {
return VFSFile.create(renameObject.getParent().getPublicURIString(), renameObject, file.getConnection(), file.getDomain());
}
} catch (KettleFileException | FileSystemException e) {
return null;
}
}
use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.
the class PartitionerPluginType method registerXmlPlugins.
protected void registerXmlPlugins() throws KettlePluginException {
for (PluginFolderInterface folder : pluginFolders) {
if (folder.isPluginXmlFolder()) {
List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
for (FileObject file : pluginXmlFiles) {
try {
Document document = XMLHandler.loadXMLFile(file);
Node pluginNode = XMLHandler.getSubNode(document, "partitioner-plugin");
if (pluginNode != null) {
registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()), this.getClass(), false, file.getParent().getURL());
}
} catch (Exception e) {
// We want to report this plugin.xml error, perhaps an XML typo or something like that...
//
log.logError("Error found while reading partitioning plugin.xml file: " + file.getName().toString(), e);
}
}
}
}
}
use of org.apache.commons.vfs2.FileObject in project pentaho-kettle by pentaho.
the class JobEntryPluginType method registerXmlPlugins.
protected void registerXmlPlugins() throws KettlePluginException {
for (PluginFolderInterface folder : pluginFolders) {
if (folder.isPluginXmlFolder()) {
List<FileObject> pluginXmlFiles = findPluginXmlFiles(folder.getFolder());
for (FileObject file : pluginXmlFiles) {
try {
Document document = XMLHandler.loadXMLFile(file);
Node pluginNode = XMLHandler.getSubNode(document, "plugin");
if (pluginNode != null) {
registerPluginFromXmlResource(pluginNode, KettleVFS.getFilename(file.getParent()), this.getClass(), false, file.getParent().getURL());
}
} catch (Exception e) {
// We want to report this plugin.xml error, perhaps an XML typo or something like that...
//
log.logError("Error found while reading job entry plugin.xml file: " + file.getName().toString(), e);
}
}
}
}
}
Aggregations