Hi, all:
I could use some advice. My method takes in a ZipInputStream object and the goal is to create a String object from each entry. My problem is this, the ZipEntry.getSize() statement returns -1 all the time, and without knowing the actual size of the entries, I can't create a byte object, and without the byte object, I can't create the String object. Please help.
Thanks
Here's my code
public ZipEntry[] findEntriesInZip( ZipInputStream objZip) throws IOException {
// Validate
if( objZip == null )
throw new NullPointerException( "Null JAR parameter passed to " +
"Zips.getFileNamesInZip" );
List objReturnList = new Vector();
try{
ZipEntry entry;
while ((entry = objZip.getNextEntry()) != null){
System.out.println(entry.getName());
long size = entry.getSize();
if (size == -1)
size = 100000; //what should I do here?
byte[] bytes = new byte[100000];
int start=0;
int chunk=0;
while (((int)size - start) > 0)
{
chunk=objZip.read(bytes,start,(int)size - start);
if (chunk==-1)
{
break;
}
start+=chunk;
}
String s = new String(bytes, 0, start+1, "UTF8");
System.out.println(s);
}