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

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

Introduction

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

Prototype

FileObject createFileSystem(FileObject file) throws FileSystemException;

Source Link

Document

Creates a layered file system.

Usage

From source file:maspack.fileutil.ZipUtility.java

public static void unzip(URIx src, final File dest) throws IOException {
    dest.mkdirs();//from   w  w w  . j  a v  a 2  s  .c  o  m

    final FileSystemManager fileSystemManager = VFS.getManager();
    final FileObject zipFileObject = fileSystemManager.resolveFile(src.toString());

    try {
        final FileObject fileSystem = fileSystemManager.createFileSystem(zipFileObject);
        try {
            fileSystemManager.toFileObject(dest).copyFrom(fileSystem, new AllFileSelector());
        } finally {
            fileSystem.close();
        }
    } finally {
        zipFileObject.close();
    }
}

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

/**
 * Appends the specified FileObjects to the list of FileObjects to search
 * for classes and resources.//from  w  w w . ja va 2s  .  com
 *
 * @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  w  w  .  ja v  a2 s. com
 * @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());
}