首页 > 其他 > 详细

断点续传时in.skip

时间:2015-09-11 02:09:40      阅读:258      评论:0      收藏:0      [点我收藏+]

断点续传里用到的一个重要方法就是inputstream的skip方法,但是在使用的时候有一点需要注意,就是skip不能保证你的输入流准确的跳过count个字节。

看看这个方法的介绍是怎么说的

?

Skips at most {@code byteCount} bytes in this stream. The number of actual
* bytes skipped may be anywhere between 0 and {@code byteCount}. 
Note the "at most" in the description of this method: this method may
* choose to skip fewer bytes than requested. Callers should <i>always</i>
* check the return value.

?所以单纯的只是 in.skip(count)是不行的,改成

int skip = (int) in.skip(m_currentBlockPos);

                    while(skip<m_currentBlockPos){

                        m_currentBlockPos-=skip;
                        skip = (int) in.skip(m_currentBlockPos);
                    }

?解决问题!

?

断点续传时in.skip

原文:http://fly-ccy.iteye.com/blog/2242415

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!