Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a ClassLoader implementation I can use to load classes from an InputStream?

I'm trying to load a JAR for which I have an InputStream into a new ClassLoader.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
126 views
Welcome To Ask or Share your Answers For Others

1 Answer

This is unlikely, as you will find if you try to do it yourself. You won't be able to randomly access an InputStream to look up classes as they're requested, so you'll have to cache the contents either in memory or in the file system.

If you cache on disk, just use URLClassLoader.

If you cache in memory, you'll need to create some sort of Map with JarInputStream and then extend ClassLoader (overriding the appropriate methods). The downside of this approach is that you keep data in RAM unnecessarily.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...