support for URL/URI Paths?

Alan Bateman Alan.Bateman at Sun.COM
Tue Jan 27 06:42:41 PST 2009


Per Bothner wrote:
> For Kawa I implmented a Path class to abstract out the
> differences between java.io.File, java.net.URL and java.net.URI,
> and provide a common clean API for them:
> http://www.gnu.org/software/kawa/api/gnu/text/Path.html
>
> Others have done the same - both KDE and Gnome have a "virtual
> file" abstraction, based on URLs.
>
> It seems like java.nio.file.Path provides much of the needed
> functionality, but it seems aimed mostly at traditional files.
> It would be really nice if there were a way to create a Path
> from an arbitrary URL,without first having to create and
> register a FileSystem.  Lots of the hooks are there, but it
> really would be nice if the functionality was provided.
>
> Of course a URL in general doesn't support all the operations
> one might expect from a File - for example you can seek it,
> or list the entries in a directory.
Yes, the API is focused on access to the file system and so is a bit 
lower level and less abstract than accessing a resource via a URL. The 
provider mechanism does allow a Path to be created from a URI but only 
if there is provider available that supports the URI scheme (the 
FileSystem could be created transparently by the provider). It's not too 
unlike requiring a stream protocol handler be available to access a 
resource via java.net.URL. It shouldn't be too difficult to create a 
generic provider that uses a stream protocol handler. It would have 
limitations but may indeed be useful to have.

-Alan.



More information about the nio-discuss mailing list