Search in sources :

Example 6 with FileSystemException

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);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileName(org.apache.commons.vfs2.FileName) RepositoryException(javax.jcr.RepositoryException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 7 with FileSystemException

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;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DelegatingFileSystemOptionsBuilder(org.apache.commons.vfs2.util.DelegatingFileSystemOptionsBuilder) RepositoryException(javax.jcr.RepositoryException) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

Example 8 with FileSystemException

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;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Example 9 with FileSystemException

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;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) FileObject(org.apache.commons.vfs2.FileObject)

Example 10 with FileSystemException

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()));
}
Also used : VFSClassLoader(org.apache.commons.vfs2.impl.VFSClassLoader) FileObject(org.apache.commons.vfs2.FileObject) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)16 FileSystemException (org.apache.commons.vfs2.FileSystemException)16 DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)8 RepositoryException (javax.jcr.RepositoryException)3 FileType (org.apache.commons.vfs2.FileType)3 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)2 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)2 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)2 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)2 File (java.io.File)1 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 UniqueFileReplicator (org.apache.accumulo.start.classloader.vfs.UniqueFileReplicator)1 FileName (org.apache.commons.vfs2.FileName)1 FileSelector (org.apache.commons.vfs2.FileSelector)1