Search in sources :

Example 26 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project spoofax by metaborg.

the class ResourceService method close.

@Override
public void close() {
    if (fileSystemManager instanceof DefaultFileSystemManager) {
        final DefaultFileSystemManager defaultFileSystemManager = (DefaultFileSystemManager) fileSystemManager;
        defaultFileSystemManager.close();
    } else {
        logger.warn("File system manager {} does not support cleaning up", fileSystemManager);
    }
}
Also used : DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager)

Example 27 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project wso2-synapse by wso2.

the class VFSUtils method releaseFail.

public static void releaseFail(FileSystemManager fsManager, FileObject fo) {
    try {
        String fullPath = fo.getName().getURI();
        int pos = fullPath.indexOf("?");
        if (pos > -1) {
            fullPath = fullPath.substring(0, pos);
        }
        FileObject failObject = fsManager.resolveFile(fullPath + ".fail");
        if (failObject.exists()) {
            failObject.delete();
        }
    } catch (FileSystemException e) {
        log.error("Couldn't release the fail for the file : " + maskURLPassword(fo.getName().getURI()));
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileObject(org.apache.commons.vfs2.FileObject)

Example 28 with FileSystemManager

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

the class FtpVFS method testftp2.

public void testftp2() throws Exception {
    FileSystemManager fsManager = VFS.getManager();
    FileObject fo = fsManager.resolveFile("ftp://ci:Zj4xyBkgjd@10.151.30.10:21/apps/tomcat7-40-tomcat-air-ticket-merchant/logs");
    // 得到远程文件列表
    FileObject[] children = fo.getChildren();
    for (int i = 0; i < children.length; i++) {
        FileObject f = children[i];
        FileContent c = f.getContent();
        File localFile = new File(f.getName().getBaseName());
        FileOutputStream out = new FileOutputStream(localFile);
        // 写入本地
        org.apache.commons.io.IOUtils.copy(c.getInputStream(), out);
        // 或使用写入
        FileObject obj = fsManager.resolveFile(this.getTargetResourceURL() + f.getName().getBaseName());
        if (!obj.exists()) {
            obj.createFile();
            obj.copyFrom(f, Selectors.SELECT_SELF);
        }
        final long size = (f.getType() == FileType.FILE) ? c.getSize() : -1;
        final long date = (f.getType() == FileType.FILE) ? c.getLastModifiedTime() : -1;
        System.out.println(f.getName().getPath() + " date:" + date + " Size:" + size);
    }
}
Also used : FileContent(org.apache.commons.vfs2.FileContent) FileOutputStream(java.io.FileOutputStream) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) File(java.io.File)

Example 29 with FileSystemManager

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

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

the class AccumuloVFSClassLoaderTest method testDefaultCacheDirectory.

@Test
public void testDefaultCacheDirectory() throws Exception {
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
    File conf = folder1.newFile("accumulo-site.xml");
    FileWriter out = new FileWriter(conf);
    out.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    out.append("<configuration>\n");
    out.append("<property>\n");
    out.append("<name>general.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("<property>\n");
    out.append("<name>general.vfs.classpaths</name>\n");
    out.append("<value></value>\n");
    out.append("</property>\n");
    out.append("</configuration>\n");
    out.close();
    Whitebox.setInternalState(AccumuloClassLoader.class, "accumuloConfigUrl", conf.toURI().toURL());
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "lock", new Object());
    AccumuloVFSClassLoader.getClassLoader();
    FileSystemManager manager = AccumuloVFSClassLoader.generateVfs();
    UniqueFileReplicator replicator = Whitebox.getInternalState(manager, "fileReplicator");
    File tempDir = Whitebox.getInternalState(replicator, "tempDir");
    String tempDirParent = tempDir.getParent();
    String tempDirName = tempDir.getName();
    String javaIoTmpDir = System.getProperty("java.io.tmpdir");
    // trim off any final separator, because java.io.File does the same.
    if (javaIoTmpDir.endsWith(File.separator)) {
        javaIoTmpDir = javaIoTmpDir.substring(0, javaIoTmpDir.length() - File.separator.length());
    }
    Assert.assertTrue(javaIoTmpDir.equals(tempDirParent));
    Assert.assertTrue(tempDirName.startsWith("accumulo-vfs-cache-"));
    Assert.assertTrue(tempDirName.endsWith(System.getProperty("user.name", "nouser")));
    Whitebox.setInternalState(AccumuloVFSClassLoader.class, "loader", (AccumuloReloadingVFSClassLoader) null);
}
Also used : FileWriter(java.io.FileWriter) File(java.io.File) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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