use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.
the class VFSDataStore method init.
@Override
public void init(String homeDir) throws RepositoryException {
overridePropertiesFromConfig();
if (baseFolderUri == null) {
throw new RepositoryException("VFS base folder URI must be set.");
}
fileSystemManager = createFileSystemManager();
FileName baseFolderName = null;
try {
baseFolderName = fileSystemManager.resolveURI(baseFolderUri);
FileSystemOptions fso = getFileSystemOptions();
if (fso != null) {
baseFolder = fileSystemManager.resolveFile(baseFolderUri, fso);
} else {
baseFolder = fileSystemManager.resolveFile(baseFolderUri);
}
baseFolder.createFolder();
} catch (FileSystemException e) {
throw new RepositoryException("Could not initialize the VFS base folder at '" + (baseFolderName == null ? "" : baseFolderName.getFriendlyURI()) + "'.", e);
}
super.init(homeDir);
}
use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.
the class VFSDataStore method createFileSystemOptions.
/**
* Builds and returns {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder}
* during the initialization.
* If {@link #fileSystemOptionsProperties} is available, this scans all the property key names starting with {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX}
* and uses the rest of the key name after the {@link #FILE_SYSTEM_OPTIONS_PROP_PREFIX} as the combination of scheme and property name
* when building a {@link FileSystemOptions} using {@link DelegatingFileSystemOptionsBuilder}.
* @return {@link FileSystemOptions} instance which is used when resolving the {@link #baseFolder} during the initialization
* @throws RepositoryException if any file system exception occurs
*/
protected FileSystemOptions createFileSystemOptions() throws RepositoryException {
FileSystemOptions fso = null;
if (fileSystemOptionsProperties != null) {
try {
fso = new FileSystemOptions();
DelegatingFileSystemOptionsBuilder delegate = new DelegatingFileSystemOptionsBuilder(getFileSystemManager());
String key;
String schemeDotPropName;
String scheme;
String propName;
String value;
int offset;
for (Enumeration<?> e = fileSystemOptionsProperties.propertyNames(); e.hasMoreElements(); ) {
key = (String) e.nextElement();
if (key.startsWith(FILE_SYSTEM_OPTIONS_PROP_PREFIX)) {
value = fileSystemOptionsProperties.getProperty(key);
schemeDotPropName = key.substring(FILE_SYSTEM_OPTIONS_PROP_PREFIX.length());
offset = schemeDotPropName.indexOf('.');
if (offset > 0) {
scheme = schemeDotPropName.substring(0, offset);
propName = schemeDotPropName.substring(offset + 1);
delegate.setConfigString(fso, scheme, propName, value);
} else {
LOG.warn("Ignoring an FileSystemOptions property in invalid format. Key: {}, Value: {}", key, value);
}
}
}
} catch (FileSystemException e) {
throw new RepositoryException("Could not create File System Options.", e);
}
}
return fso;
}
use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.
the class VFSUtils method createChildFile.
/**
* Creates a child file by the {@code name} under the {@code baseFolder} and retrieves the created file.
* @param baseFolder base folder object
* @param name child file name
* @return a child file by the {@code name} under the {@code baseFolder} and retrieves the created file
* @throws DataStoreException if any file system exception occurs
*/
static FileObject createChildFile(FileObject baseFolder, String name) throws DataStoreException {
FileObject childFile = null;
try {
childFile = baseFolder.resolveFile(name);
if (!childFile.exists()) {
childFile.createFile();
childFile = baseFolder.getChild(childFile.getName().getBaseName());
}
} catch (FileSystemException e) {
throw new DataStoreException("Could not create a child file, '" + name + "' under " + baseFolder.getName().getFriendlyURI(), e);
}
return childFile;
}
use of org.apache.commons.vfs2.FileSystemException in project jackrabbit by apache.
the class VFSUtils method createChildFolder.
/**
* Creates a child folder by the {@code name} under the {@code baseFolder} and retrieves the created folder.
* @param baseFolder base folder object
* @param name child folder name
* @return a child folder by the {@code name} under the {@code baseFolder} and retrieves the created folder
* @throws DataStoreException if any file system exception occurs
*/
static FileObject createChildFolder(FileObject baseFolder, String name) throws DataStoreException {
FileObject childFolder = null;
try {
childFolder = baseFolder.resolveFile(name);
if (!childFolder.exists()) {
childFolder.createFolder();
childFolder = baseFolder.getChild(childFolder.getName().getBaseName());
}
} catch (FileSystemException e) {
throw new DataStoreException("Could not create a child folder, '" + name + "' under " + baseFolder.getName().getFriendlyURI(), e);
}
return childFolder;
}
use of org.apache.commons.vfs2.FileSystemException in project metron by apache.
the class VFSClassloaderUtil method configureClassloader.
/**
* Create a classloader backed by a virtual filesystem which can handle the following URI types:
* * res - resource files
* * jar
* * tar
* * bz2
* * tgz
* * zip
* * HDFS
* * FTP
* * HTTP/S
* * file
* @param paths A set of comma separated paths. The paths are URIs or URIs with a regex pattern at the end.
* @return A classloader object if it can create it
* @throws FileSystemException
*/
public static Optional<ClassLoader> configureClassloader(String paths) throws FileSystemException {
if (paths.trim().isEmpty()) {
return Optional.empty();
}
FileSystemManager vfs = generateVfs();
FileObject[] objects = resolve(vfs, paths);
if (objects == null || objects.length == 0) {
return Optional.empty();
}
return Optional.of(new VFSClassLoader(objects, vfs, vfs.getClass().getClassLoader()));
}
Aggregations