• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struggling with ZipInputStream and ZipEntry

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
 
Enjoy the full beauty of the english language. Embedded in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic