-
Notifications
You must be signed in to change notification settings - Fork 275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Obtaining a URL from a jimfs Path #13
Comments
It looks like for this to work there has to be a Manually, you can create an implementation and then do: URL url = new URL(null, path.toUri().toString(), new JimfsURLStreamHandler()); It's also possible to use The final piece of complexity is just how the |
You don't need to change the default stream handler factory for this to work. If you have a Handler class in a sub-package named 'jimfs', then you can simply set the "java.protocol.handler.pkgs" system property to the parent package. It would be very helpful if the Handler class and a UrlConnection class shipped with jimfs. Here are the classes I use:
|
For URLs to work, Java has to be able to find a URLStreamHandler implementation for the URL protocol/scheme. There isn't any really ideal way to do this programatically, but what this CL does is add "com.google.common" to the "java.protocol.handler.pkgs" system property when JimfsFileSystemProvider is initialized. This means that when Java tries to create a URL with the "jimfs" protocol, it'll look for "jimfs.Handler" under "com.google.common", find it and use it. (Documentation of that behavior found here: http://docs.oracle.com/javase/8/docs/api/java/net/URL.html#URL-java.lang.String-java.lang.String-int-java.lang.String-) Fixes Github issue #13. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=86627713
This is in now, using the |
A framework I'm testing internally needs to obtain an URL from a passed in path. For testing, I'd like to use jimfs, but obtaining a URL from a jimfs path seems not to be possible. Calling
path.toUri().toURL()
throws a MalformedURLException with message:java.net.MalformedURLException: unknown protocol: jimfs
. Is this something fixable or something to live with? Here is a simpe test case to reproduce:Edit: I just found out that one can implement a
URLStreamHandlerFactory
to accomplish this. You might consider to ship a suitable implementation for jimfs.The text was updated successfully, but these errors were encountered: