`
fly_宇光十色
  • 浏览: 63379 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

断点续传时in.skip

    博客分类:
  • Java
 
阅读更多

断点续传里用到的一个重要方法就是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);
                    }

 解决问题!

 

1
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics