Example usage for org.apache.commons.vfs2 FileSystemManager canCreateFileSystem

List of usage examples for org.apache.commons.vfs2 FileSystemManager canCreateFileSystem

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileSystemManager canCreateFileSystem.

Prototype

boolean canCreateFileSystem(FileObject file) throws FileSystemException;

Source Link

Document

Determines if a layered file system can be created for a given file.

Usage

From source file:com.seeburger.vfs2.util.VFSClassLoader.java

/**
 * Appends the specified FileObjects to the list of FileObjects to search
 * for classes and resources./*www  .  ja v a 2  s . c o  m*/
 *
 * @param manager The FileSystemManager.
 * @param files the FileObjects to append to the search path.
 * @throws FileSystemException if an error occurs.
 */
private void addFileObjects(final FileSystemManager manager, final FileObject[] files)
        throws FileSystemException {
    for (int i = 0; i < files.length; i++) {
        FileObject file = files[i];
        if (!file.exists()) {
            // Does not exist - skip
            continue;
        }

        // TODO - use federation instead
        if (file.getType().hasContent() && manager.canCreateFileSystem(file)) {
            // Use contents of the file
            file = manager.createFileSystem(file);
        }

        resources.add(file);
    }
}

From source file:org.geoserver.backuprestore.utils.BackupUtils.java

/**
 * Extracts the archive file {@code archiveFile} to {@code targetFolder}; both shall previously exist.
 *
 * @param archiveFile/*from   w ww.ja va2  s  .  c  om*/
 * @param targetFolder
 * @throws IOException
 */
public static void extractTo(Resource archiveFile, Resource targetFolder) throws IOException {
    FileSystemManager manager = VFS.getManager();
    String sourceURI = resolveArchiveURI(archiveFile);

    FileObject source = manager.resolveFile(sourceURI);
    if (manager.canCreateFileSystem(source)) {
        source = manager.createFileSystem(source);
    }
    FileObject target = manager
            .createVirtualFileSystem(manager.resolveFile(targetFolder.dir().getAbsolutePath()));

    FileSelector selector = new AllFileSelector() {
        @Override
        public boolean includeFile(FileSelectInfo fileInfo) {
            LOGGER.fine("Uncompressing " + fileInfo.getFile().getName().getFriendlyURI());
            return true;
        }
    };
    target.copyFrom(source, selector);
    source.close();
    target.close();
    manager.closeFileSystem(source.getFileSystem());
}