Search in sources :

Example 16 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project pivot by apache.

the class TerraVFSBrowserSkin method rootDirectoryChanged.

@Override
public void rootDirectoryChanged(VFSBrowser fileBrowser, FileObject previousRootDirectory) {
    ArrayList<FileObject> path = new ArrayList<>();
    // FileSystemManager manager = fileBrowser.getManager();
    FileObject rootDirectory = fileBrowser.getRootDirectory();
    try {
        FileObject ancestorDirectory = rootDirectory.getParent();
        while (ancestorDirectory != null) {
            path.add(ancestorDirectory);
            ancestorDirectory = ancestorDirectory.getParent();
        }
    } catch (FileSystemException fse) {
        throw new RuntimeException(fse);
    }
    @SuppressWarnings("unchecked") ArrayList<FileObject> drives = (ArrayList<FileObject>) driveListButton.getListData();
    if (refreshRoots) {
        // TODO: this is ugly -- need to do much better at managing drive
        // list with VFS
        // There is an open question on the Dev list about adding
        // "getFileRoots()" to the VFS API.
        /*
             * try { FileObject[] roots = new FileObject[1]; roots[0] =
             * manager.resolveFile
             * (manager.getBaseFile().getName().getRoot().getURI()); drives =
             * new ArrayList<>(); for (int i = 0; i < roots.length; i++) {
             * FileObject root = roots[i]; if (root.exists()) {
             * drives.add(root); } } driveListButton.setListData(drives); }
             * catch (FileSystemException fse) { throw new
             * RuntimeException(fse); }
             */
        refreshRoots = false;
    }
    driveListButton.setVisible(drives.getLength() > 1);
    FileObject drive;
    if (path.getLength() == 0) {
        drive = rootDirectory;
    } else {
        drive = path.get(path.getLength() - 1);
    }
    driveListButton.setSelectedItem(drive);
    pathListButton.setListData(path);
    pathListButton.setButtonData(rootDirectory);
    pathListButton.setEnabled(rootDirectory.getName().getDepth() > 0);
    goUpButton.setEnabled(pathListButton.isEnabled());
    goHomeButton.setEnabled(!rootDirectory.equals(homeDirectory));
    fileScrollPane.setScrollTop(0);
    fileScrollPane.setScrollLeft(0);
    searchTextInput.setText("");
    fileTableView.requestFocus();
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ArrayList(org.apache.pivot.collections.ArrayList) FileObject(org.apache.commons.vfs2.FileObject)

Example 17 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project jackrabbit by apache.

the class VFSDataStore method createFileSystemManager.

/**
 * Creates a {@link FileSystemManager} instance.
 * @return a {@link FileSystemManager} instance.
 * @throws RepositoryException if an error occurs creating the manager.
 */
protected FileSystemManager createFileSystemManager() throws RepositoryException {
    FileSystemManager fileSystemManager = null;
    try {
        if (getFileSystemManagerClassName() == null) {
            fileSystemManager = new StandardFileSystemManager();
        } else {
            final Class<?> mgrClass = Class.forName(getFileSystemManagerClassName());
            fileSystemManager = (FileSystemManager) mgrClass.newInstance();
        }
        if (fileSystemManager instanceof DefaultFileSystemManager) {
            ((DefaultFileSystemManager) fileSystemManager).init();
        }
    } catch (final FileSystemException e) {
        throw new RepositoryException("Could not initialize file system manager of class: " + getFileSystemManagerClassName(), e);
    } catch (final Exception e) {
        throw new RepositoryException("Could not create file system manager of class: " + getFileSystemManagerClassName(), e);
    }
    return fileSystemManager;
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) RepositoryException(javax.jcr.RepositoryException) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException)

Example 18 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager 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 19 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager 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 {
    LOG.debug("Configuring class loader with paths = {}", paths);
    if (paths.trim().isEmpty()) {
        LOG.debug("No paths provided. Not returning a ClassLoader.");
        return Optional.empty();
    }
    FileSystemManager vfs = generateVfs();
    FileObject[] objects = resolve(vfs, paths);
    if (objects == null || objects.length == 0) {
        LOG.debug("No Classloader able to be resolved from provided paths. Not returning a ClassLoader.");
        return Optional.empty();
    }
    LOG.debug("vfs = {}, objects = {}", vfs, objects);
    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)

Example 20 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project scheduling by ow2-proactive.

the class VFSZipperZIPTest method testUnzipEmptyContent.

@Test
public void testUnzipEmptyContent() throws IOException, InterruptedException {
    Files.createFile(archivePath);
    FileSystemManager fsManager = VFS.getManager();
    VFSZipper.ZIP.unzip(Files.newInputStream(archivePath), fsManager.resolveFile(outputPath.toUri()));
    assertThat(outputPath.toFile().listFiles()).isNull();
}
Also used : FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test)

Aggregations

FileSystemManager (org.apache.commons.vfs2.FileSystemManager)30 FileObject (org.apache.commons.vfs2.FileObject)29 FileSystemException (org.apache.commons.vfs2.FileSystemException)21 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)17 File (java.io.File)12 IOException (java.io.IOException)11 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)7 Test (org.junit.Test)6 FileContent (org.apache.commons.vfs2.FileContent)4 FileSystemOptions (org.apache.commons.vfs2.FileSystemOptions)4 OutputStream (java.io.OutputStream)3 RepositoryException (javax.jcr.RepositoryException)3 FileName (org.apache.commons.vfs2.FileName)3 SoftRefFilesCache (org.apache.commons.vfs2.cache.SoftRefFilesCache)3 FileOutputStream (java.io.FileOutputStream)2 FileWriter (java.io.FileWriter)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 Map (java.util.Map)2