How create jar archive file with the crc, compressed size, and size set.
907722Dec 27 2011 — edited Jan 1 2012I'm having trouble setting the size and other attributes when creating a jar archive. This is the code used to create the archive:
....
ZipOutputStream jos = new ZipOutputStream( new FileOutputStream(output) );
for( String entryName : images.keySet() )
{
ZipEntry je = new ZipEntry(entryName);
File f = images.get(entryName);
jos.putNextEntry(je);
InputStream fis = new FileInputStream(f);
int i;
byte[] buff = new byte[2048];
while( (i=fis.read(buff)) != -1)
{
jos.write(buff,0,i);
}
jos.finish();
jos.closeEntry();
fis.close();
}
jos.finish();
jos.close();
...
This is the code I'm using to read the archive:
...
JarInputStream jis = new JarInputStream( new FileInputStream(jarFile) );
JarEntry je;
while( (je = jis.getNextJarEntry()) != null )
{
if( je.getSize()>0 && !entries.contains(je.getName()))
{
.... //do something
}
}
jis.close();
...
What I can't figure out is why the getSize() returns -1 for my archive (along with the crc and compressed size calls)? I have other archives which do not return -1 which makes me believe the code reading the archive is OK. Yet I can use jar tvf myfile.jar from the command line and it lists every file with the size so it makes me think the writing code is ok too? Other than the size, crc, and compressed size attributes all being "unknown" everything else about the archive seems fine (I can uncompress, I can using the contents in classpath, etc).
Any clues would be great. Thanks!
I've flailed away a bit using setSize() on the creation side of things but it didn't work, plus it doesn't see like I should have to do that anyway.