public FileObject resolveFile()

in commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystem.java [97:173]


    public FileObject resolveFile(final FileName name) throws FileSystemException {
        synchronized (this) {
            if (this.fs == null) {
                final String hdfsUri = name.getRootURI();
                final HdfsFileSystemConfigBuilder builder = HdfsFileSystemConfigBuilder.getInstance();
                final FileSystemOptions options = getFileSystemOptions();
                final String[] configNames = builder.getConfigNames(options);
                final Path[] configPaths = builder.getConfigPaths(options);
                final URL[] configURLs = builder.getConfigURLs(options);
                final InputStream configStream = builder.getConfigInputStream(options);
                final Configuration configConfiguration = builder.getConfigConfiguration(options);

                final Configuration conf = new Configuration(true);
                conf.set(FileSystem.FS_DEFAULT_NAME_KEY, hdfsUri);

                // Load any alternate configuration parameters that may have been specified
                // no matter where they might come from
                if (configNames != null) {
                    for (final String configName : configNames) {
                        log.debug("Adding HDFS configuration resource: " + configName);
                        conf.addResource(configName);
                    }
                }
                if (configPaths != null) {
                    for (final Path path : configPaths) {
                        log.debug("Adding HDFS configuration path: " + path);
                        conf.addResource(path);
                    }
                }
                if (configURLs != null) {
                    for (final URL url : configURLs) {
                        log.debug("Adding HDFS configuration URL: " + url);
                        conf.addResource(url);
                    }
                }
                if (configStream != null) {
                    log.debug("Adding HDFS configuration stream");
                    conf.addResource(configStream);
                }
                if (configConfiguration != null) {
                    log.debug("Adding HDFS configuration object");
                    conf.addResource(configConfiguration);
                }

                try {
                    fs = FileSystem.get(conf);
                } catch (final IOException e) {
                    log.error("Error connecting to filesystem " + hdfsUri, e);
                    throw new FileSystemException("Error connecting to filesystem " + hdfsUri, e);
                }
            }
        }

        final boolean useCache = null != getFileSystemManager().getFilesCache();
        FileObject fileObject = useCache ? getFileFromCache(name) : null;
        if (null == fileObject) {
            String path;
            try {
                path = URLDecoder.decode(name.getPath(), "UTF-8");
            } catch (final UnsupportedEncodingException e) {
                path = name.getPath();
            }
            final Path filePath = new Path(path);
            fileObject = new HdfsFileObject((AbstractFileName) name, this, fs, filePath);
            fileObject = decorateFileObject(fileObject);
            if (useCache) {
                this.putFileToCache(fileObject);
            }
        }
        /*
          resync the file information if requested
         */
        if (getFileSystemManager().getCacheStrategy().equals(CacheStrategy.ON_RESOLVE)) {
            fileObject.refresh();
        }
        return fileObject;
    }