【发布时间】:2010-03-26 01:09:01
【问题描述】:
我有这段代码,我希望它能够告诉我下载了多少数据(并很快将其放入进度条中),然后通过我的 Sax Parser 解析结果。如果我基本上注释掉 //xr.parse(new InputSource(request.getInputStream())); 行上方的所有内容并交换 xr.parse 的结束,它工作正常。但此刻,我的 Sax 解析器告诉我我什么都没有。它与 is.read(缓冲区)部分有关吗?
另外,请注意,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. */;
任何人都可以帮助我吗??
亲切的问候,
安迪
【问题讨论】:
标签: java android sax httpurlconnection