Apache VFS (7): File Manager File Parsing Method

Source: Internet
Author: User
Navigation of this series of articles

Apache VFS (1): Basic Introduction

Apache VFS (2): file monitoring and monitoring

Apache VFS (3): file filter and Selector

Apache VFS (4): Events

Apache VFS (5): use it!

Apache VFS (6): several important conceptual Interfaces

Apache VFS (7): File Manager File Parsing Method

In general, when we use Apache VFS, the File Manager obtained directly from the VFS object isStandardFileSystemManager

, Standardfilesystemmanager is inherited from defaultfilesystemmanager. The parsing FileDefaultFileSystemManager

.

In most cases, you will provide a URI to locate your file system. For example:Ftp: // yourftp/rootdir or http: // yourweb/rootdi

R or file: // C:/rootdir

And pass the string as a parameter to standardfilesystemmanger.ResolveFile Method

Parses the URI and returns a fileobject object. Let's take a look at this method:

This method has five reload methods that accept different parameters, but the core method has only one:

/**

* Resolves a URI, realtive to a base file with specified filesystem

* Configuration

*/

Public FileObject resolveFile (final FileObject baseFile, final String uri,

Final FileSystemOptions fileSystemOptions)

Throws FileSystemException

{

Final FileObject realBaseFile;

If (baseFile! = Null & VFS. isUriStyle ()

& BaseFile. getName (). getType () = FileType. FILE)

{

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 (URI );

If (scheme! = NULL)

{

// An absolute URI-locate the provider

Final fileprovider provider = (fileprovider) 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

If (defaultprovider = NULL)

{

Throw new FileSystemException ("vfs. impl/unknown-scheme.error ",

New Object []

{Scheme, uri });

}

Return defaultProvider. findFile (realBaseFile, uri,

FileSystemOptions );

}

// Assume a relative name-use the supplied base file

If (realBaseFile = null)

{

Throw new FileSystemException ("vfs. impl/find-rel-file.error", uri );

}

Return realBaseFile. resolveFile (uri );

}

 

 

Source: http://alartin.javaeye.com/blog/92436

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.