I am trying to read file from the JarInputStream and the size of file is returning -1. I am accessing Jar file from the URL as a inputStream.
URLConnection con = url.openConnection();
JarInputStream jis = new JarInputStream(con.getInputStream());
JarEntry je = null;
while ((je = jis.getNextJarEntry()) != null) {
htSizes.put(je.getName(), new Integer((int) je.getSize()));
if (je.isDirectory()) {
continue;
}
int size = (int) je.getSize();
// -1 means unknown size.
if (size == -1) {
size = ((Integer) htSizes.get(je.getName())).intValue();
}
byte[] b = new byte[(int) size];
int rb = 0;
int chunk = 0;
while (((int) size - rb) > 0) {
chunk = jis.read(b, rb, (int) size - rb);
if (chunk == -1) {
break;
}
rb += chunk;
}
// add to internal resource hashtable
htJarContents.put(je.getName(), baos.toByteArray());
}