K
Karsten Wutzke
Hi all!
Subject says it all... how do I create a JarFile/ZipFile instance from
a byte array without outputting the byte[] to a temporary file and
reading it back via the JarFile/ZipFile constructors??
Currently I do it via temp file (which sucks):
------------------
File flTempJar = new File(RuntimeConfig.getIoTempDir(),
"deleteme.jar");
FileOutputStream fos = new FileOutputStream(flTempJar);
fos.write(uncompressedBytes);
fos.close();
System.out.println("Saving extracted library temporarily as file '" +
flTempJar + "' - it sucks......");
JarFile jar = new JarFile(flTempJar);
try
{
boolean wasSuccessful = flTempJar.delete();
}
catch ( Exception e )
{
System.err.println("Temporary JAR file '" + flTempJar + "'
couldn't be deleted!");
}
//now do something with the JarFile instance....
------------------
I can't and don't want anyone using this code to require disk access.
When a SecurityManager prohibits this, this code becomes useless.
Furthermore, since this is CLASSLOADER code, all classes to be found
and loaded by this class loader will never be available...
Can anyone help what to do here?
Looks like I have to create my own JarFile subclass to provide the
byte[] constructor.
If there's a different way, I'm all ears...
I wonder who wrote the ZipFile and JarFile classes... how could they
forget byte[] and/or stream constructors? beats me...
TIA
Karsten
PS: Using a 3rd library here is out of the question since the code is
the 3rd party library class loader's code itself...
Subject says it all... how do I create a JarFile/ZipFile instance from
a byte array without outputting the byte[] to a temporary file and
reading it back via the JarFile/ZipFile constructors??
Currently I do it via temp file (which sucks):
------------------
File flTempJar = new File(RuntimeConfig.getIoTempDir(),
"deleteme.jar");
FileOutputStream fos = new FileOutputStream(flTempJar);
fos.write(uncompressedBytes);
fos.close();
System.out.println("Saving extracted library temporarily as file '" +
flTempJar + "' - it sucks......");
JarFile jar = new JarFile(flTempJar);
try
{
boolean wasSuccessful = flTempJar.delete();
}
catch ( Exception e )
{
System.err.println("Temporary JAR file '" + flTempJar + "'
couldn't be deleted!");
}
//now do something with the JarFile instance....
------------------
I can't and don't want anyone using this code to require disk access.
When a SecurityManager prohibits this, this code becomes useless.
Furthermore, since this is CLASSLOADER code, all classes to be found
and loaded by this class loader will never be available...
Can anyone help what to do here?
Looks like I have to create my own JarFile subclass to provide the
byte[] constructor.
If there's a different way, I'm all ears...
I wonder who wrote the ZipFile and JarFile classes... how could they
forget byte[] and/or stream constructors? beats me...
TIA
Karsten
PS: Using a 3rd library here is out of the question since the code is
the 3rd party library class loader's code itself...