Issue: Modules can only open resources as streams

David M. Lloyd david.lloyd at redhat.com
Tue Mar 22 21:02:38 UTC 2016


On 03/22/2016 12:13 PM, forax at univ-mlv.fr wrote:
> ----- Mail original -----
>> De: "David M. Lloyd" <david.lloyd at redhat.com>
>> À: "Remi Forax" <forax at univ-mlv.fr>
>> Cc: jpms-spec-experts at openjdk.java.net
>> Envoyé: Mardi 22 Mars 2016 14:02:54
>> Objet: Re: Issue: Modules can only open resources as streams
>>
>> URI is definitely better than URL.  However it doesn't really solve the
>> points I listed below.  It would really be useful for a resource to be a
>> handle with size, stream, and origin class loader/module fields.
>
> from an URI, you can call toURL() and get access to the size, the stream etc.
>
> thinking a little more on this, you can already have access to the URI of a resource of a module by using the ModuleReader, from the ModuleReference, from the Configuration, from the Layer ...
>
>    try(ModuleReader reader = module.getLayer().configuration().findModule(module.getName()).get().reference().open()) {
>      Optional<URI> uri = reader.find(resourseName);
>      ...
>    }
>
> obviously, directly exposing the ModuleReader might be a good idea :)

Knowing which module your resource came from is definitely a key 
requirement.  I'm not sure what URI actually will benefit in this case 
though.  Not only do you have to switch it to URL to actually use it to 
load anything, but by returning URI, modules lose the ability to send 
back URLs with custom behaviors.  Also it means that every resource 
needs an absolute location, which is an unnecessary constraint as far as 
I can see.

-- 
- DML


More information about the jpms-spec-experts mailing list