org.apache.commons.vfs2.FileSystemOptions Java Examples

The following examples show how to use org.apache.commons.vfs2.FileSystemOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Http5FileSystem.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Construct {@code Http4FileSystem}.
 *
 * @param rootName root base name
 * @param fileSystemOptions file system options
 * @param httpClient {@link HttpClient} instance
 * @param httpClientContext {@link HttpClientContext} instance
 */
protected Http5FileSystem(final FileName rootName, final FileSystemOptions fileSystemOptions, final HttpClient httpClient,
        final HttpClientContext httpClientContext) {
    super(rootName, null, fileSystemOptions);

    final String rootURI = getRootURI();
    final int offset = rootURI.indexOf(':');
    final char lastCharOfScheme = (offset > 0) ? rootURI.charAt(offset - 1) : 0;

    // if scheme is 'http*s' or 'HTTP*S', then the internal base URI should be 'https'. 'http' otherwise.
    if (lastCharOfScheme == 's' || lastCharOfScheme == 'S') {
        this.internalBaseURI = URI.create("https" + rootURI.substring(offset));
    } else {
        this.internalBaseURI = URI.create("http" + rootURI.substring(offset));
    }

    this.httpClient = httpClient;
    this.httpClientContext = httpClientContext;
}
 
Example #2
Source File: PublishUtil.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static FileObject createVFSConnection( final FileSystemManager fileSystemManager,
    final AuthenticationData loginData ) throws FileSystemException {
  if ( fileSystemManager == null ) {
    throw new NullPointerException();
  }
  if ( loginData == null ) {
    throw new NullPointerException();
  }

  final String versionText = loginData.getOption( SERVER_VERSION );
  final int version = ParserUtil.parseInt( versionText, SERVER_VERSION_SUGAR );

  final String normalizedUrl = normalizeURL( loginData.getUrl(), version );
  final FileSystemOptions fileSystemOptions = new FileSystemOptions();
  final PentahoSolutionsFileSystemConfigBuilder configBuilder = new PentahoSolutionsFileSystemConfigBuilder();
  configBuilder.setTimeOut( fileSystemOptions, getTimeout( loginData ) * 1000 );
  configBuilder.setUserAuthenticator( fileSystemOptions, new StaticUserAuthenticator( normalizedUrl, loginData
      .getUsername(), loginData.getPassword() ) );
  return fileSystemManager.resolveFile( normalizedUrl, fileSystemOptions );
}
 
Example #3
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    final GenericFileName rootName = (GenericFileName) name;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Http4FileSystemConfigBuilder builder = Http4FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fileSystemOptions, authData);
        httpClient = createHttpClient(builder, rootName, fileSystemOptions);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Http4FileSystem(rootName, fileSystemOptions, httpClient, httpClientContext);
}
 
Example #4
Source File: Webdav4sFileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@link FileSystem}.
 * <p>
 * If you're looking at this method and wondering how to get a FileSystemOptions object bearing the proxy host and
 * credentials configuration through to this method so it's used for resolving a
 * {@link org.apache.commons.vfs2.FileObject FileObject} in the FileSystem, then be sure to use correct signature of
 * the {@link org.apache.commons.vfs2.FileSystemManager FileSystemManager} resolveFile method.
 *
 * @see org.apache.commons.vfs2.impl.DefaultFileSystemManager#resolveFile(FileObject, String, FileSystemOptions)
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final GenericFileName rootName = (GenericFileName) name;
    // TODO: need to check null to create a non-null here???
    final FileSystemOptions fsOpts = fileSystemOptions == null ? new FileSystemOptions() : fileSystemOptions;

    UserAuthenticationData authData = null;
    HttpClient httpClient = null;
    HttpClientContext httpClientContext = null;

    try {
        final Webdav4FileSystemConfigBuilder builder = Webdav4FileSystemConfigBuilder.getInstance();
        authData = UserAuthenticatorUtils.authenticate(fsOpts, Webdav4FileProvider.AUTHENTICATOR_TYPES);
        httpClientContext = createHttpClientContext(builder, rootName, fsOpts, authData);
        httpClient = createHttpClient(builder, rootName, fsOpts);
    } finally {
        UserAuthenticatorUtils.cleanup(authData);
    }

    return new Webdav4FileSystem(rootName, fsOpts, httpClient, httpClientContext) {
    };
}
 
Example #5
Source File: ResourceFileProvider.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Locates a file object, by absolute URI.
 *
 * @param baseFile The base file.
 * @param uri The URI of the file to locate.
 * @param fileSystemOptions The FileSystem options.
 * @return the FileObject.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    final FileName fileName;
    if (baseFile != null) {
        fileName = parseUri(baseFile.getName(), uri);
    }
    else {
        fileName = parseUri(null, uri);
    }
    final String resourceName = fileName.getPath();

    ClassLoader classLoader = ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions);
    if (classLoader == null) {
        classLoader = getClass().getClassLoader();
    }
    FileSystemException.requireNonNull(classLoader, "vfs.provider.url/badly-formed-uri.error", uri);
    final URL url = classLoader.getResource(resourceName);

    FileSystemException.requireNonNull(url, "vfs.provider.url/badly-formed-uri.error", uri);

    return getContext().getFileSystemManager().resolveFile(url.toExternalForm());
}
 
Example #6
Source File: TarFileSystem.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
protected TarFileSystem(final AbstractFileName rootName, final FileObject parentLayer,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    super(rootName, parentLayer, fileSystemOptions);

    // Make a local copy of the file
    file = parentLayer.getFileSystem().replicateFile(parentLayer, Selectors.SELECT_SELF);

    // Open the Tar file
    if (!file.exists()) {
        // Don't need to do anything
        tarFile = null;
        return;
    }

    // tarFile = createTarFile(this.file);
}
 
Example #7
Source File: AbstractSftpProviderTestCase.java    From commons-vfs with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the base folder for tests.
 */
@Override
public FileObject getBaseTestFolder(final FileSystemManager manager) throws Exception {
    String uri = getSystemTestUriOverride();
    if (uri == null) {
        uri = ConnectionUri;
    }

    final FileSystemOptions fileSystemOptions = new FileSystemOptions();
    final SftpFileSystemConfigBuilder builder = SftpFileSystemConfigBuilder.getInstance();
    builder.setStrictHostKeyChecking(fileSystemOptions, "no");
    builder.setUserInfo(fileSystemOptions, new TrustEveryoneUserInfo());
    builder.setIdentityRepositoryFactory(fileSystemOptions, new TestIdentityRepositoryFactory());
    final FileObject fileObject = manager.resolveFile(uri, fileSystemOptions);
    this.fileSystem = (SftpFileSystem) fileObject.getFileSystem();
    return fileObject;
}
 
Example #8
Source File: HttpFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
protected HttpFileObject(final AbstractFileName name, final FS fileSystem,
        final HttpFileSystemConfigBuilder builder) {
    super(name, fileSystem);
    final FileSystemOptions fileSystemOptions = fileSystem.getFileSystemOptions();
    urlCharset = builder.getUrlCharset(fileSystemOptions);
    userAgent = builder.getUserAgent(fileSystemOptions);
    followRedirect = builder.getFollowRedirect(fileSystemOptions);
}
 
Example #9
Source File: Http5FileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private HttpHost getProxyHttpHost(final Http5FileSystemConfigBuilder builder,
        final FileSystemOptions fileSystemOptions) {
    final String proxyHost = builder.getProxyHost(fileSystemOptions);
    final int proxyPort = builder.getProxyPort(fileSystemOptions);

    if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
        return new HttpHost(proxyHost, proxyPort);
    }

    return null;
}
 
Example #10
Source File: AbstractOriginatingFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Locates a file object, by absolute URI.
 *
 * @param baseFile The base file object.
 * @param uri The URI of the file to locate
 * @param fileSystemOptions The FileSystem options.
 * @return The located FileObject
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Parse the URI
    final FileName name;
    try {
        name = parseUri(baseFile != null ? baseFile.getName() : null, uri);
    } catch (final FileSystemException exc) {
        throw new FileSystemException("vfs.provider/invalid-absolute-uri.error", uri, exc);
    }

    // Locate the file
    return findFile(name, fileSystemOptions);
}
 
Example #11
Source File: FtpsClientFactory.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
@Override
protected void setupOpenConnection(final FTPSClient client, final FileSystemOptions fileSystemOptions)
        throws IOException {
    final FtpsDataChannelProtectionLevel level = builder.getDataChannelProtectionLevel(fileSystemOptions);
    if (level != null) {
        // '0' means streaming, that's what we do!
        try {
            client.execPBSZ(0);
            client.execPROT(level.name());
        } catch (final SSLException e) {
            throw new FileSystemException("vfs.provider.ftps/data-channel.level", e, level.toString());
        }
    }
}
 
Example #12
Source File: KettleSftpFileSystemConfigBuilderTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void recognizesAndSetsUserHomeDirProperty() throws Exception {
  final String fullName = Const.VFS_USER_DIR_IS_ROOT;
  final String name = fullName.substring( "vfs.sftp.".length() );
  final String vfsInternalName = SftpFileSystemConfigBuilder.class.getName() + ".USER_DIR_IS_ROOT";

  final FileSystemOptions opts = new FileSystemOptions();
  KettleSftpFileSystemConfigBuilder builder = KettleSftpFileSystemConfigBuilder.getInstance();
  builder.setParameter( opts, name, "true", fullName, "sftp://fake-url:22" );

  Method getOption = ReflectionUtils.findMethod( opts.getClass(), "getOption", Class.class, String.class );
  getOption.setAccessible( true );
  Object value = ReflectionUtils.invokeMethod( getOption, opts, builder.getConfigClass(), vfsInternalName );
  assertEquals( true, value );
}
 
Example #13
Source File: OtherConnectionDetailsProvider.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override public FileSystemOptions getOpts( OtherConnectionDetails otherConnectionDetails ) {
  if ( otherConnectionDetails == null ) {
    return null;
  }
  StaticUserAuthenticator auth =
          new StaticUserAuthenticator( otherConnectionDetails.getHost(), otherConnectionDetails.getUsername(),
                  otherConnectionDetails.getPassword() );
  FileSystemOptions opts = new FileSystemOptions();
  try {
    DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator( opts, auth );
  } catch ( FileSystemException fse ) {
    // Ignore and return default options
  }
  return opts;
}
 
Example #14
Source File: VFSHelper.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static FileSystemOptions getOpts( String file, String connection ) {
  if ( connection != null ) {
    VFSConnectionDetails vfsConnectionDetails =
      (VFSConnectionDetails) ConnectionManager.getInstance().getConnectionDetails( file, connection );
    VFSConnectionProvider<VFSConnectionDetails> vfsConnectionProvider =
      (VFSConnectionProvider<VFSConnectionDetails>) ConnectionManager.getInstance().getConnectionProvider( file );
    if ( vfsConnectionDetails != null && vfsConnectionProvider != null ) {
      return vfsConnectionProvider.getOpts( vfsConnectionDetails );
    }
  }
  return null;
}
 
Example #15
Source File: Http4FileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private HttpHost getProxyHttpHost(final Http4FileSystemConfigBuilder builder,
        final FileSystemOptions fileSystemOptions) {
    final String proxyHost = builder.getProxyHost(fileSystemOptions);
    final int proxyPort = builder.getProxyPort(fileSystemOptions);

    if (proxyHost != null && proxyHost.length() > 0 && proxyPort > 0) {
        return new HttpHost(proxyHost, proxyPort);
    }

    return null;
}
 
Example #16
Source File: SftpFileSystemConfigBuilder.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the identity infos.
 *
 * @param opts The FileSystem options.
 * @return the array of identity info.
 * @see #setIdentityInfo
 */
public IdentityInfo[] getIdentityInfo(final FileSystemOptions opts) {
    final IdentityProvider[] infos = getIdentityProvider(opts);
    if (infos != null) {
        final List<IdentityInfo> list = new ArrayList<>(infos.length);
        for (final IdentityProvider identityProvider : infos) {
            if (identityProvider instanceof IdentityInfo) {
                list.add((IdentityInfo) identityProvider);
            }
        }
        return list.toArray(new IdentityInfo[list.size()]);
    }
    return null;
}
 
Example #17
Source File: FtpClientFactory.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private void configureClient(final FileSystemOptions fileSystemOptions, final C client) {
    final String key = builder.getEntryParser(fileSystemOptions);
    if (key != null) {
        final FTPClientConfig config = new FTPClientConfig(key);

        final String serverLanguageCode = builder.getServerLanguageCode(fileSystemOptions);
        if (serverLanguageCode != null) {
            config.setServerLanguageCode(serverLanguageCode);
        }
        final String defaultDateFormat = builder.getDefaultDateFormat(fileSystemOptions);
        if (defaultDateFormat != null) {
            config.setDefaultDateFormatStr(defaultDateFormat);
        }
        final String recentDateFormat = builder.getRecentDateFormat(fileSystemOptions);
        if (recentDateFormat != null) {
            config.setRecentDateFormatStr(recentDateFormat);
        }
        final String serverTimeZoneId = builder.getServerTimeZoneId(fileSystemOptions);
        if (serverTimeZoneId != null) {
            config.setServerTimeZoneId(serverTimeZoneId);
        }
        final String[] shortMonthNames = builder.getShortMonthNames(fileSystemOptions);
        if (shortMonthNames != null) {
            final StringBuilder shortMonthNamesStr = new StringBuilder(BUFSZ);
            for (final String shortMonthName : shortMonthNames) {
                if (shortMonthNamesStr.length() > 0) {
                    shortMonthNamesStr.append("|");
                }
                shortMonthNamesStr.append(shortMonthName);
            }
            config.setShortMonthNames(shortMonthNamesStr.toString());
        }

        client.configure(config);
    }
}
 
Example #18
Source File: HttpProviderTestCase.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
private void testResloveFolderSlash(final String uri, final boolean followRedirect) throws FileSystemException {
    VFS.getManager().getFilesCache().close();
    final FileSystemOptions opts = new FileSystemOptions();
    HttpFileSystemConfigBuilder.getInstance().setFollowRedirect(opts, followRedirect);
    try (final FileObject file = VFS.getManager().resolveFile(uri, opts)) {
        checkReadTestsFolder(file);
    } catch (final FileNotFolderException e) {
        // Expected: VFS HTTP does not support listing children yet.
    }
}
 
Example #19
Source File: DefaultLocalFileProvider.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the file system.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    // Create the file system
    final LocalFileName rootName = (LocalFileName) name;
    return new LocalFileSystem(rootName, rootName.getRootFile(), fileSystemOptions);
}
 
Example #20
Source File: MockFileProvider.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
@Override
public FileObject findFile( FileObject arg0, String arg1, FileSystemOptions arg2 ) throws FileSystemException {
  // TODO Auto-generated method stub
  return null;
}
 
Example #21
Source File: WebdavFileSystem.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected WebdavFileSystem(final GenericFileName rootName, final HttpClient client,
        final FileSystemOptions fileSystemOptions) {
    super(rootName, client, fileSystemOptions);
}
 
Example #22
Source File: S3AFileProvider.java    From hop with Apache License 2.0 4 votes vote down vote up
protected FileSystem doCreateFileSystem( final FileName name, final FileSystemOptions fileSystemOptions )
  throws FileSystemException {
  return new S3AFileSystem( name, fileSystemOptions );
}
 
Example #23
Source File: SmbFileProvider.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the file system.
 */
@Override
protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    return new SmbFileSystem(name, fileSystemOptions);
}
 
Example #24
Source File: CrawlerPack.java    From CrawlerPack with Apache License 2.0 4 votes vote down vote up
/**
 * 透過 Apache Common VFS 套件 取回遠端的資源
 *
 * 能使用的協定參考:
 * @see <a href="https://commons.apache.org/proper/commons-vfs/filesystems.html">commons-vfs filesystems</a>
 */
public String getFromRemote(String uri){

    // clear cache
    fileSystem.getFilesCache().close();

    String remoteContent ;
    String remoteEncoding = "utf-8";

    log.debug("getFromRemote: Loading remote URI=" + uri);
    FileContent fileContent ;

    try {

        FileSystemOptions fsOptions = new FileSystemOptions();
        // set userAgent
        HttpFileSystemConfigBuilder.getInstance().setUserAgent(fsOptions, userAgent);

        // set cookie if cookies set
        if (0 < this.cookies.size()) {
            HttpFileSystemConfigBuilder.getInstance().setCookies(fsOptions, getCookies(uri));
        }

        log.debug("getFromRemote: userAgent=" + userAgent);
        log.debug("getFromRemote: cookieSize=" + cookies.size());
        log.debug("getFromRemote: cookies=" + cookies.toString());

        fileContent = fileSystem.resolveFile(uri, fsOptions).getContent();

        // 2016-03-22 only pure http/https auto detect encoding
        if ("http".equalsIgnoreCase(uri.substring(0, 4))) {
            fileContent.getSize();  // pass a bug {@link https://issues.apache.org/jira/browse/VFS-427}
            remoteEncoding = fileContent.getContentInfo().getContentEncoding();
        }

        log.debug("getFromRemote: remoteEncoding=" + remoteEncoding + "(auto detect) ");

        // 2016-03-21 修正zip file getContentEncoding 為null
        if (null == remoteEncoding) remoteEncoding = "utf-8";

        if (!"utf".equalsIgnoreCase(remoteEncoding.substring(0, 3))) {
            log.debug("getFromRemote: remote content encoding=" + remoteEncoding);

            // force charset encoding if setRemoteEncoding set
            if (!"utf".equalsIgnoreCase(encoding.substring(0, 3))) {
                remoteEncoding = encoding;
            } else {
                // auto detecting encoding
                remoteEncoding = detectCharset(IOUtils.toByteArray(fileContent.getInputStream()));
                log.debug("getFromRemote: real encoding=" + remoteEncoding);
            }
        }

        // 透過  Apache VFS 取回指定的遠端資料
        // 2016-02-29 fixed
        remoteContent = IOUtils.toString(fileContent.getInputStream(), remoteEncoding);

    } catch(FileSystemException fse){
        log.warn("getFromRemote: FileSystemException=" + fse.getMessage());
        remoteContent =null;
    }catch(IOException ioe){
        // return empty
        log.warn("getFromRemote: IOException=" + ioe.getMessage());
        remoteContent =null;
    }catch(StringIndexOutOfBoundsException stre){
        log.warn("getFromRemote: StringIndexOutOfBoundsException=" + stre.getMessage());
        log.warn("getFromRemote: uri=" + uri );
        log.warn(stre.getMessage());
        remoteContent =null;
    }

    clearCookies();

    log.debug("getFromRemote: remoteContent=\n" + remoteContent);
    // any exception will return "null"
    return remoteContent;
}
 
Example #25
Source File: SmbUserAuthenticator.java    From otroslogviewer with Apache License 2.0 4 votes vote down vote up
public SmbUserAuthenticator(AuthStore authStore, String url, FileSystemOptions fileSystemOptions) {
  super(authStore, url, fileSystemOptions);
}
 
Example #26
Source File: UseCentralsFromSessionUserAuthenticator.java    From otroslogviewer with Apache License 2.0 4 votes vote down vote up
public UseCentralsFromSessionUserAuthenticator(AuthStore authStore,AuthStore sessionAuthStore, String url,
                                               FileSystemOptions fileSystemOptions, AbstractUiUserAuthenticator otrosUserAuthenticator) {
  super(authStore, url, fileSystemOptions);
  this.sessionAuthStore = sessionAuthStore;
  this.otrosUserAuthenticator = otrosUserAuthenticator;
}
 
Example #27
Source File: AbstractUiUserAuthenticator.java    From otroslogviewer with Apache License 2.0 4 votes vote down vote up
protected FileSystemOptions getFileSystemOptions() {
  return fileSystemOptions;
}
 
Example #28
Source File: RepositoryVfsProvider.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public FileObject createFileSystem( String scheme, FileObject file, FileSystemOptions fileSystemOptions )
  throws FileSystemException {
  throw new NotImplementedException();
}
 
Example #29
Source File: FTPClientWrapper.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
protected FTPClientWrapper(final GenericFileName root, final FileSystemOptions fileSystemOptions)
        throws FileSystemException {
    this.root = root;
    this.fileSystemOptions = fileSystemOptions;
    getFtpClient(); // fail-fast
}
 
Example #30
Source File: DefaultFileSystemManager.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves a URI, relative to a base file with specified FileSystem configuration.
 *
 * @param baseFile The base file.
 * @param uri The file name. May be a fully qualified or relative path or a url.
 * @param fileSystemOptions Options to pass to the file system.
 * @return A FileObject representing the target file.
 * @throws FileSystemException if an error occurs accessing the file.
 */
public FileObject resolveFile(final FileObject baseFile, final String uri,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final FileObject realBaseFile;
    if (baseFile != null && VFS.isUriStyle() && baseFile.getName().isFile()) {
        realBaseFile = baseFile.getParent();
    } else {
        realBaseFile = baseFile;
    }
    // TODO: use resolveName and use this name to resolve the fileObject

    UriParser.checkUriEncoding(uri);

    if (uri == null) {
        throw new IllegalArgumentException();
    }

    // Extract the scheme
    final String scheme = UriParser.extractScheme(getSchemes(), uri);
    if (scheme != null) {
        // An absolute URI - locate the provider
        final FileProvider provider = providers.get(scheme);
        if (provider != null) {
            return provider.findFile(realBaseFile, uri, fileSystemOptions);
        }
        // Otherwise, assume a local file
    }

    // Handle absolute file names
    if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
        return localFileProvider.findLocalFile(uri);
    }

    if (scheme != null) {
        // An unknown scheme - hand it to the default provider
        FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
        return defaultProvider.findFile(realBaseFile, uri, fileSystemOptions);
    }

    // Assume a relative name - use the supplied base file
    FileSystemException.requireNonNull(realBaseFile, "vfs.impl/find-rel-file.error", uri);

    return realBaseFile.resolveFile(uri);
}