Search in sources :

Example 6 with FileSystemManager

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

the class VFSUtils method isFailRecord.

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

Example 7 with FileSystemManager

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

the class VFSTransportSenderTest method getSoftReferenceMap.

private Map<?, ?> getSoftReferenceMap(VFSTransportSender vfsTransportSender) throws NoSuchFieldException, IllegalAccessException {
    Field field = VFSTransportSender.class.getDeclaredField("fsManager");
    field.setAccessible(true);
    FileSystemManager fsm = (FileSystemManager) field.get(vfsTransportSender);
    FilesCache fileCache = fsm.getFilesCache();
    SoftRefFilesCache softRefFilesCache = (SoftRefFilesCache) fileCache;
    Field field1 = SoftRefFilesCache.class.getDeclaredField("refReverseMap");
    field1.setAccessible(true);
    return (Map<?, ?>) (Map) field1.get(softRefFilesCache);
}
Also used : Field(java.lang.reflect.Field) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) Map(java.util.Map) SoftRefFilesCache(org.apache.commons.vfs2.cache.SoftRefFilesCache) FilesCache(org.apache.commons.vfs2.FilesCache)

Example 8 with FileSystemManager

use of org.apache.commons.vfs2.FileSystemManager in project pentaho-platform by pentaho.

the class PentahoXmlaServlet method makeCatalogLocator.

@Override
protected CatalogLocator makeCatalogLocator(ServletConfig servletConfig) {
    return new ServletContextCatalogLocator(servletConfig.getServletContext()) {

        @Override
        public String locate(String catalogPath) {
            if (catalogPath.startsWith("mondrian:")) {
                // $NON-NLS-1$
                try {
                    FileSystemManager fsManager = VFS.getManager();
                    SolutionRepositoryVfsFileObject catalog = (SolutionRepositoryVfsFileObject) fsManager.resolveFile(catalogPath);
                    catalogPath = "solution:" + catalog.getFileRef();
                } catch (FileSystemException e) {
                    logger.error(e.getMessage());
                }
            } else {
                catalogPath = super.locate(catalogPath);
            }
            return catalogPath;
        }
    };
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ServletContextCatalogLocator(mondrian.spi.impl.ServletContextCatalogLocator) DefaultFileSystemManager(org.apache.commons.vfs2.impl.DefaultFileSystemManager) FileSystemManager(org.apache.commons.vfs2.FileSystemManager) SolutionRepositoryVfsFileObject(org.pentaho.platform.repository.solution.filebased.SolutionRepositoryVfsFileObject)

Example 9 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 10 with FileSystemManager

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

the class FtpVFS method testsftp.

/**
 * 测试末通过
 *
 * @throws Exception
 */
public void testsftp() throws Exception {
    FileSystemManager fsManager = VFS.getManager();
    FileSystemOptions opts = new FileSystemOptions();
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
    // 显示目录
    FileObject fo = fsManager.resolveFile("sftp://ci:Zj4xyBkgjd@10.151.30.10:22/apps/tomcat7-40-tomcat-air-ticket-merchant/logs/", opts);
    // 得到远程文件列表
    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) FileSystemOptions(org.apache.commons.vfs2.FileSystemOptions)

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