FYI

Basically the secret to getting `getResource()' and `getResourceAsStream' 
to work my custom class loader was subclassing the `URLStreamHandler' and 
`URLConnection' to handle the `custom': protocol such that a URL 
would work, such

        ``custom:/SOMEHOST/path/to/file/dukey.gif''

where "custom" is the protocol. "SOMEHOST" is the machine name and the
rest is the file.

Then the std java `URL' class can handle the protocol `custom' and you 
would just call `URL.openConnection()' to get an `INputStream'

However my new CustomLoaderClass is not fully compatible with the 
primordial for some reason, because it does not work at all well with the 
`JEditorPane' and I got `Premature end of JPEG' when loading a JPEG file.
This is a real pity because it would nice to the package any application 
resources (ie GIF, HTML, JPEGs and AUs) also within the JAR file.

Anyway the idea for the custom stream handler came from the O'Reilly `Java 
Network Programming' book as I said before. This is place where I will stop.

Peter

______________________________ Reply Separator _________________________________
Subject: Re: Implementating ClassLoader.getResource?
Author:  Peter Pilgrim at London
Date:    10/03/99 13:54


Here is my CustomClassLoader written in a two days at least to load 
class type data from a modified class path. I started my class with the 
Java in a Nutshell Book example.

Basically it emulates the primordial class loader.

It does almost everything.

It does not implement `getResource( String name )' object, because it needs 
URLStreamHandler object to implement a new URL protocol.

I'd like it do set up a URL of 
`privateresource:/DUMMY_ZIP_HOST/+/foo/bar/duke.gif'

Hence the protocol is `privateresource' just the `http' or `ftp' or
even `systemresource'. So what one needs is a specialised protocol handler 
to complete the class loader otherwise `getResourceAsInputStream' will 
work. For my application it much better to use URLs, because that is what
god intended reference for, instead opening input streams. Anyway I digress ... 
My invented specialised URLStreamHandler would find the GIF in the modified 
class path. This result would be the GIF image resource "duke.gif".

I suspect that the URL string "systemresource:/ZIP7/+/foo/bar/duke.gif'
is interpret like this. The dummy hostname `/ZIP7/' is really means the 7th ZIP 
file inside a private internally maintained (Vector) list of ZIP filename paths 
which is grokked from the primordial CLASSPATH. The '+' is just a magic 
placeholder to identify the filename in the zip. Ah this look my sort of URL, ce
n'est pas?

All you do, then, is find the 7th one and get the fully qualified filename to it
say "/opt/my/loard/frogger/hendrix.zip' and then retrieve the zip file entry
and then get the input stream for it. And that your custom URLStreamHandler 
witten done. The only problem is how do you change the URL stream handler 
factory or customise it so that you add another protocol a runtime?

Any help appreciated

Peter


BTW: CC-Mail is really a pile of s**t, the proper name of the attachment is 
`CustomClassLoader.java'

______________________________ Reply Separator _________________________________
Subject: Re: Implementating ClassLoader.getResource?
Author:  dulitz ([EMAIL PROTECTED]) at lon-mime 
Date:    10/03/99 13:09


Hi Peter,

Sorry, I don't know the answer to your question.

I do want to mention, though, that over the last few months a few people 
on java-linux have expressed a desire to use or look at a ClassLoader 
such as the one you have written.  No biggie, but it might save a few 
people a day of work each.

FYI,
daniel dulitz

Valley Technologies, Inc.               Peak Performance Real-Time DSP 
State College, PA


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to