Open mumu7818 opened 8 years ago
在调用了request.cancel()后,表面上看起来像是取消下载了,但实质服务器还能给客户端发数据。 分析了原因,是因为DataParser中stream.close()不能立即关闭,需要接收完全部数据,inputstream才能关闭导致。这说明数据链路还是连接的,这样取消下载就没什么意义,还是会消耗流量,但我不知道怎么修改,有大牛知道怎么修改吗? public T readFromNetStream(InputStream stream, long len, String charSet) throws IOException { if (stream != null) { try { this.data = parseNetStream(stream, len, charSet); } finally { stream.close(); } } return this.data; }
这样看你数据量的大小; 如果你数据小于 框架buffer size 4096 那么无法停止,如果你数据大于4096那么会在完成一波buffer后及时停止。代码如下: while (!request.isCancelledOrInterrupted() && (l = is.read(buff)) > 0) { swapStream.write(buff, 0, l); readLength += l; }
在调用了request.cancel()后,表面上看起来像是取消下载了,但实质服务器还能给客户端发数据。 分析了原因,是因为DataParser中stream.close()不能立即关闭,需要接收完全部数据,inputstream才能关闭导致。这说明数据链路还是连接的,这样取消下载就没什么意义,还是会消耗流量,但我不知道怎么修改,有大牛知道怎么修改吗? public T readFromNetStream(InputStream stream, long len, String charSet) throws IOException { if (stream != null) { try { this.data = parseNetStream(stream, len, charSet); } finally { stream.close(); } } return this.data; }