Prepare to read 10k each time from the input stream, but the actual length of each read is not always 10k, maybe even 0, and three test results are as follows:
First run result (read 10 times):
contentlength:52450
7872
88
10240
10240
176
3472
3472
10240
3472
3178
File name: Nvdcve-2.0-modified.xml
File Size: 711356
Second run result (read 11 times):
contentlength:52450
7872
6944
3472
3472
6944
3472
3472
3472
6944
3472
2914
File name: Nvdcve-2.0-modified.xml
File Size: 711356
Third run result (read 10 times):
contentlength:52450
7872
3472
3472
3472
3472
9660
10240
10240
220
330
File name: Nvdcve-2.0-modified.xml
File Size: 711356
Url url = new url ("Http://static.nvd.nist.gov/feeds/xml/cve/nvdcve-2.0-Modified.xml.zip") ;//sun.net.www.protocol.http.httpurlconnectionhttpurlconnection con = (HttpURLConnection) Url.openconnection (); Con.setrequestproperty ("User-agent", "mozilla/5.0 chrome/31.0.1650.63 safari/537.36 "),/*1, read compressed file stream */system.out.println (" ContentLength: " + con.getcontentlength ()); Nputstream is = con.getinputstream (); int len = -1; byte[] b = new byte[10240];//ready to read into 10kbytearrayoutputstream os = new bytearrayoutputstream ();while ((Len = is.read (b)) > -1) { System.out.println (len);//The length of each read is not always 10k os.write (B, 0, len);} Con.disconnect ();/*2, decompression, can be extracted directly from the URL connection of the input stream decompression Zipinputstream (Con.getinputstream ()) */zipinputstream zis = new zipinputstream (New bytearrayinputstream (OS. Tobytearray ())); Zipentry ze = zis.getnextentry (); System.out.println ("File name:" + ze.getname ()); Bytearrayoutputstream zos = new bytearrayoutputstream ();while (len = Zis.read (b)) > -1) { zos.write (B, 0, len); SYSTEM.OUT.PRINTLN ("File Size:" + zos.size ());//system.out.println (zos.tostring ());//Print file contents
HTTP Zip compressed file read and decompress