Question

I am trying to read a Zip archive with a ZipInputStream. I cycle through all the entries without any problem like so:

  try {
                while((ze = zis.getNextEntry()) != null) {
                    Log.v(this.toString(), "Name = " + name);

                } 
       } catch (IOException e) {
            // TODO Auto-generated catch block
            //e.printStackTrace();
            Log.e(this.toString(), "IOException in creating ZipEntry.");
        }   

When I try to use the zis variable to read the same zip file in another function, in the same manner as described above, line ze = zis.getNextEntry() returns null. This is understandable because the end of the stream has been reached.

My question(s):
1. How do I "rewind" a stream?
2. Is there an alternate to creating a temporary ZipInputStream and using that in the next function where I am required to read the zip file again?

Was it helpful?

Solution

There is no way to rewind a ZipInputStream in Java.

The only alternative is to restructure your code to only have to read the stream once. This would most likely be advantageous to you (depending on the context of your situation), as it would not require unzipping the data more than once.

Maybe you could unzip the data to a temporary cache directory instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top