Jar file from byte array




















Table of Contents. Improve Article. Save Article. Like Article. Last Updated : 28 Jan, It extends the class java. ZipInputStream with support for reading an optional Manifest entry. The Manifest can be used to store meta-information about the JAR file and its entries. If verification has been enabled, any invalid signature detected while positioning the stream for the next entry will result in an exception.

If len is not zero, the method blocks until some input is available; otherwise, no bytes are read and 0 is returned.

If it is failed again, throw a ClassNotFoundException directly. So if we want to implement a classloader to use bytes array, we should override the method of findClass and it is enough. While we are calling getResourceAsStream from any classloader, actually it will try look up the resources from its parent first and it just same as loading Java class.

Below is the sequence of how Java look up a resource name. If the resource file cannot be found by its parent, it will try load the resource file by findResource itself. If it is failed again, return null directly. Asked 8 years, 8 months ago. Active 4 years, 11 months ago. Viewed 7k times. Improve this question. Nicolas Filotto Bradley Odell Bradley Odell 1, 2 2 gold badges 13 13 silver badges 27 27 bronze badges.

I inherited a similar class loader in a project I used to work on. It was extremely slow there too. Aside from that it caused me all sorts of headaches. In the end the lesson learned was not use a custom class loader unless you really need to. I have to ask I mean, the Jars could be of arbitrary size, it sounds like a really bad idea to keep all the loaded Jars in the memory forever. It also mean you'll keep the Jar bytes, the cached entries plus the loaded classes Add a comment.

Active Oldest Votes. The best you can do First you have no need to use JarInputStream as it only adds the support of the manifest to the class ZipInputStream which we don't really care here. Improve this answer. Nicolas Filotto Nicolas Filotto If you save the file as temporary, you can than just use the standard URLClassloader, can't you?

What I meant was that your 'ideal solution' could be in that case simplified by extending the UrlClassLoader as you dump the file there anyway. JanCetkovsky probably yes, but here the idea was to show the main difference in more details between the 2 approaches, the first one with a time complexity of O n and the other one with a time complexity of O 1 — Nicolas Filotto.



0コメント

  • 1000 / 1000