Search in sources :

Example 31 with VFS

use of org.apache.commons.vfs2.VFS in project accumulo by apache.

the class VfsClassLoaderTest method testFileMonitor.

@Test
public void testFileMonitor() throws Exception {
    MyFileMonitor listener = new MyFileMonitor();
    DefaultFileMonitor monitor = new DefaultFileMonitor(listener);
    monitor.setRecursive(true);
    FileObject testDir = vfs.resolveFile(TEST_DIR.toUri().toString());
    monitor.addFile(testDir);
    monitor.start();
    // Copy jar file to a new file name
    URL jarPath = this.getClass().getResource("/HelloWorld.jar");
    Path src = new Path(jarPath.toURI().toString());
    Path dst = new Path(TEST_DIR, "HelloWorld2.jar");
    this.hdfs.copyFromLocalFile(src, dst);
    // VFS-487 significantly wait to avoid failure
    Thread.sleep(7000);
    Assert.assertTrue(listener.isFileCreated());
    // Update the jar
    jarPath = this.getClass().getResource("/HelloWorld.jar");
    src = new Path(jarPath.toURI().toString());
    dst = new Path(TEST_DIR, "HelloWorld2.jar");
    this.hdfs.copyFromLocalFile(src, dst);
    // VFS-487 significantly wait to avoid failure
    Thread.sleep(7000);
    Assert.assertTrue(listener.isFileChanged());
    this.hdfs.delete(dst, false);
    // VFS-487 significantly wait to avoid failure
    Thread.sleep(7000);
    Assert.assertTrue(listener.isFileDeleted());
    monitor.stop();
}
Also used : Path(org.apache.hadoop.fs.Path) FileObject(org.apache.commons.vfs2.FileObject) DefaultFileMonitor(org.apache.commons.vfs2.impl.DefaultFileMonitor) URL(java.net.URL) Test(org.junit.Test)

Example 32 with VFS

use of org.apache.commons.vfs2.VFS in project accumulo by apache.

the class AccumuloDFSBase method miniDfsClusterSetup.

@BeforeClass
public static void miniDfsClusterSetup() {
    System.setProperty("java.io.tmpdir", System.getProperty("user.dir") + "/target");
    // System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
    // Logger.getRootLogger().setLevel(Level.ERROR);
    // Put the MiniDFSCluster directory in the target directory
    System.setProperty("test.build.data", "target/build/test/data");
    // Setup HDFS
    conf = new Configuration();
    conf.set("hadoop.security.token.service.use_ip", "true");
    conf.set("dfs.datanode.data.dir.perm", MiniDFSUtil.computeDatanodeDirectoryPermission());
    // 1M blocksize
    conf.setLong(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 1024 * 1024);
    try {
        cluster = new MiniDFSCluster.Builder(conf).build();
        cluster.waitClusterUp();
        // We can't assume that the hostname of "localhost" will still be "localhost" after
        // starting up the NameNode. We may get mapped into a FQDN via settings in /etc/hosts.
        HDFS_URI = cluster.getFileSystem().getUri();
    } catch (IOException e) {
        throw new RuntimeException("Error setting up mini cluster", e);
    }
    // Set up the VFS
    vfs = new DefaultFileSystemManager();
    try {
        vfs.setFilesCache(new DefaultFilesCache());
        vfs.addProvider("res", new org.apache.commons.vfs2.provider.res.ResourceFileProvider());
        vfs.addProvider("zip", new org.apache.commons.vfs2.provider.zip.ZipFileProvider());
        vfs.addProvider("gz", new org.apache.commons.vfs2.provider.gzip.GzipFileProvider());
        vfs.addProvider("ram", new org.apache.commons.vfs2.provider.ram.RamFileProvider());
        vfs.addProvider("file", new org.apache.commons.vfs2.provider.local.DefaultLocalFileProvider());
        vfs.addProvider("jar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("http", new org.apache.commons.vfs2.provider.http.HttpFileProvider());
        vfs.addProvider("https", new org.apache.commons.vfs2.provider.https.HttpsFileProvider());
        vfs.addProvider("ftp", new org.apache.commons.vfs2.provider.ftp.FtpFileProvider());
        vfs.addProvider("ftps", new org.apache.commons.vfs2.provider.ftps.FtpsFileProvider());
        vfs.addProvider("war", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("par", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("ear", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("sar", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("ejb3", new org.apache.commons.vfs2.provider.jar.JarFileProvider());
        vfs.addProvider("tmp", new org.apache.commons.vfs2.provider.temp.TemporaryFileProvider());
        vfs.addProvider("tar", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("tbz2", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("tgz", new org.apache.commons.vfs2.provider.tar.TarFileProvider());
        vfs.addProvider("bz2", new org.apache.commons.vfs2.provider.bzip2.Bzip2FileProvider());
        vfs.addProvider("hdfs", new HdfsFileProvider());
        vfs.addExtensionMap("jar", "jar");
        vfs.addExtensionMap("zip", "zip");
        vfs.addExtensionMap("gz", "gz");
        vfs.addExtensionMap("tar", "tar");
        vfs.addExtensionMap("tbz2", "tar");
        vfs.addExtensionMap("tgz", "tar");
        vfs.addExtensionMap("bz2", "bz2");
        vfs.addMimeTypeMap("application/x-tar", "tar");
        vfs.addMimeTypeMap("application/x-gzip", "gz");
        vfs.addMimeTypeMap("application/zip", "zip");
        vfs.setFileContentInfoFactory(new FileContentInfoFilenameFactory());
        vfs.setFilesCache(new SoftRefFilesCache());
        vfs.setReplicator(new DefaultFileReplicator(new File(System.getProperty("java.io.tmpdir"), "accumulo-vfs-cache-" + System.getProperty("user.name", "nouser"))));
        vfs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        vfs.init();
    } catch (FileSystemException e) {
        throw new RuntimeException("Error setting up VFS", e);
    }
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) HdfsFileProvider(org.apache.commons.vfs2.provider.hdfs.HdfsFileProvider) FileSystemException(org.apache.commons.vfs2.FileSystemException) FileContentInfoFilenameFactory(org.apache.commons.vfs2.impl.FileContentInfoFilenameFactory) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) DefaultFilesCache(org.apache.commons.vfs2.cache.DefaultFilesCache) IOException(java.io.IOException) DefaultFileReplicator(org.apache.commons.vfs2.impl.DefaultFileReplicator) File(java.io.File) BeforeClass(org.junit.BeforeClass)

Example 33 with VFS

use of org.apache.commons.vfs2.VFS in project javautils by jiadongpo.

the class SFTPClientVFS method getFileObject.

public static FileObject getFileObject(String vfsFilename) throws Exception {
    try {
        FileSystemManager fsManager = getInstance().getFileSystemManager();
        boolean relativeFilename = true;
        String[] schemes = fsManager.getSchemes();
        for (int i = 0; i < schemes.length && relativeFilename; i++) {
            if (vfsFilename.startsWith(schemes[i] + ":")) {
                relativeFilename = false;
            // We have a VFS URL, load any options for the file system driver
            // fsOptions = buildFsOptions( space, fsOptions, vfsFilename, schemes[i] );
            }
        }
        String filename;
        if (vfsFilename.startsWith("\\\\")) {
            File file = new File(vfsFilename);
            filename = file.toURI().toString();
        } else {
            if (relativeFilename) {
                File file = new File(vfsFilename);
                filename = file.getAbsolutePath();
            } else {
                filename = vfsFilename;
            }
        }
        FileObject fileObject = null;
        return fsManager.resolveFile(filename);
    } catch (IOException e) {
        throw new Exception("Unable to get VFS File object for filename '" + cleanseFilename(vfsFilename) + "' : " + e.getMessage());
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException)

Example 34 with VFS

use of org.apache.commons.vfs2.VFS in project javautils by jiadongpo.

the class SFTPClientVFS method getFileObject.

public static FileObject getFileObject(String vfsFilename) throws Exception {
    try {
        FileSystemManager fsManager = getInstance().getFileSystemManager();
        boolean relativeFilename = true;
        String[] schemes = fsManager.getSchemes();
        for (int i = 0; i < schemes.length && relativeFilename; i++) {
            if (vfsFilename.startsWith(schemes[i] + ":")) {
                relativeFilename = false;
            // We have a VFS URL, load any options for the file system driver
            // fsOptions = buildFsOptions( space, fsOptions, vfsFilename, schemes[i] );
            }
        }
        String filename;
        if (vfsFilename.startsWith("\\\\")) {
            File file = new File(vfsFilename);
            filename = file.toURI().toString();
        } else {
            if (relativeFilename) {
                File file = new File(vfsFilename);
                filename = file.getAbsolutePath();
            } else {
                filename = vfsFilename;
            }
        }
        FileObject fileObject = null;
        return fsManager.resolveFile(filename);
    } catch (IOException e) {
        throw new Exception("Unable to get VFS File object for filename '" + cleanseFilename(vfsFilename) + "' : " + e.getMessage());
    }
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) StandardFileSystemManager(org.apache.commons.vfs2.impl.StandardFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) File(java.io.File) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException)

Example 35 with VFS

use of org.apache.commons.vfs2.VFS 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)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)50 IOException (java.io.IOException)27 KettleException (org.pentaho.di.core.exception.KettleException)23 FileSystemException (org.apache.commons.vfs2.FileSystemException)22 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)20 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)20 Result (org.pentaho.di.core.Result)19 File (java.io.File)18 FileSystemManager (org.apache.commons.vfs2.FileSystemManager)11 DefaultFileSystemManager (org.apache.commons.vfs2.impl.DefaultFileSystemManager)11 ResultFile (org.pentaho.di.core.ResultFile)11 VFSClassLoader (org.apache.commons.vfs2.impl.VFSClassLoader)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 StandardFileSystemManager (org.apache.commons.vfs2.impl.StandardFileSystemManager)6 URL (java.net.URL)4 Matcher (java.util.regex.Matcher)4 Pattern (java.util.regex.Pattern)4