Getting the size of a ZipInputStream

Do I still need to find / evaluate the size of the ZipInputStream before we fully read the stream?

For example, we can get the metadata of a record with getNextEntry before we can read user data.

The input stream has an available method () to return an estimate of the number of bytes that can be read from this input stream, but I cannot find a similar method for ZipInputStream.

+5
source share
3 answers

If you only have a thread, then I don’t think so.

zip , ( ) . , .

+2

ZipInputStream (), 0 1.

, FileInputStream, zip , ZipInputStream. .

 public class ZipUtil {

    public static void main(String[] args) throws Exception {
        ZipInputStream zis = null;

        FileInputStream fis = new FileInputStream("C:/catalina.zip");
        int size = fis.available();
        System.out.println("size in KB : " + size/1024);
        zis = new ZipInputStream(fis);        

        ZipEntry ze;
        while ((ze = zis.getNextEntry()) != null) {
            System.out.println(ze.getName());
        }
    }
}
+1

() ,

. . Javadoc , .

ZipInputStream.

This is strange because there. However, it returns zero, which is the best estimate that it can make, how much can be read without blocking.

Why? Because (a) it is a stream, and (ii) it is an archived stream. There is no way to know how much there is without reading all of this; and there’s no way to know how many of them can be read without blocking,

+1
source

All Articles