我有这段代码,我希望能够告诉我下载了多少数据(并很快将其放入进度条中),然后通过我的 Sax Parser 解析结果。如果我基本上注释掉 //xr.parse(new InputSource(request.getInputStream()));上面的所有内容 行并交换 xr.parse 的结束,它工作正常。但此刻,我的 Sax 解析器告诉我我什么都没有。是不是有什么关系。读取(缓冲)部分?
另外,请注意, request 是具有各种签名的 HttpURLConnection 。
/*Input stream to read from our connection*/
InputStream is = request.getInputStream();
/*we make a 2 Kb buffer to accelerate the download, instead of reading the file a byte at once*/
byte [ ] buffer = new byte [ 2048 ] ;
/*How many bytes do we have already downloaded*/
int totBytes,bytes,sumBytes = 0;
totBytes = request.getContentLength () ;
while ( true ) {
/*How many bytes we got*/
bytes = is.read (buffer);
/*If no more byte, we're done with the download*/
if ( bytes <= 0 ) break;
sumBytes+= bytes;
Log.v("XML", sumBytes + " of " + totBytes + " " + ( ( float ) sumBytes/ ( float ) totBytes ) *100 + "% done" );
}
/* Parse the xml-data from our URL. */
// OLD, and works if comment all the above
//xr.parse(new InputSource(request.getInputStream()));
xr.parse(new InputSource(is))
/* Parsing has finished. */;
任何人都可以帮助我吗?
亲切的问候,
安迪