Reputation: 4223
Suppose I have a java process that is receiving a runnable jar file from a trusted process in the form of a byte [], is there a way to invoke it without having to write the jar file to disk and then invoke it(start a new process that is running the jar)?
Upvotes: 5
Views: 920
Reputation: 17923
Here is one way you can accomplish it:
ByteArrayInputStream
from the byte []
received.Now use JarInputStream
to create in-memory representation of the jar file.
ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
JarInputStream jis = new JarInputStream(bis);
This way you have the jar loaded in the memory.
Upvotes: 8
Reputation: 5445
The easiest approach would be to write it to a ramdisk and avoid the in-memory idea completely.
Upvotes: 2