开发者

Implementing ClassLoader.getResource(String) without a protocol handler

My class loader resolves resources to a source that does not have a url handler eg it gets resources from a database. This of course poses a problem for ClassLoader.getResource(String) which returns a URL. For the URL.openConnection() etc to work i need a protocol handler, which poses an additionoal problem. How cna i map the URL to my data provider without installing a custom Url proto开发者_JS百科col handler which requires me to set a system property at startup. The problem with url protocol handlers is they are static and must be set at startup while my class loaders are dynamic and can come from many places.

Is there are way to solve this elegantly without a protocol handler ?


Well, if you're implementing ClassLoader.getResource(String) yourself can you not use the constructor for URL that takes in the protocol handler as one of its arguments?

public URL(String protocol,
           String host,
           int port,
           String file,
           URLStreamHandler handler)
    throws MalformedURLException
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜