java - ZipInputStream doesn't report *actual* (i.e. compressed) bytes read -
Love this website! My point is as follows:
I am reading a zip file that is coming to a network with an HTTP "PUT" request. The request title tells me that the content-length (say) 1Mb creates the following code ZipInputStream, and saves zip content for the files in the current directory:
ZipInputStream zis = new ZipInputStream (inputStream ); Zipantri ZF; Long kilobytes = 0; While ((ze = zis.getNextEntry ()) = null) {BufferedOutputStream Outstream = New BufferedOutputStream (New FileOutputStream (ze.getName ())); Byte [] buffer = new byte [4096]; Int i; While ((i = zis.read (buffer))! = -1) {totalBytesRead + = i; OutStream.write (buffer, 0, i); } Outstream.close (); } Inputstream.close (); When all is said and done, totalBytesRead is approximately 1.5 MB (depending on the compression of the files, anything can happen!). What I want to know is one way to know how many actual bytes have been read from the original input stream ? For each zipped entry, ze.getSize () and ze.getCompressedSize () return -1 both (ie it does not know). This information is needed for a progress bar to show how many bytes of the zip file were read to me.
Suggestions? Can I possibly do zip intestust subclasses and find out how many bytes in it are reading it from the wrapped inputstream?
Thanks in advance!
Of course, it seems reasonable.
There are basically two options: read all the bytes, archive them (in memory or file), count them, then press them; Or they come in as the calculation of them. The former seems unworthy, and will later require subclass of InputStream , which has the ability to read the bytes. I can not think of one in the standard library, but the implementation is probably there - then again it would be easy to write your own.
Comments
Post a Comment