http断点续传简单实现(3)
//停止文件下载
public void sitestop()
{
bstop = true;
for(int i=0;i<nstartpos.length;i++)
filesplitterfetch[i].splitterstop();
}
}
//负责部分文件的抓取
**filesplitterfetch.java
*/
package netfox;
import java.io.*;
import java.net.*;
public class filesplitterfetch extends thread {
string surl; //file url
long nstartpos; //file snippet start position
long nendpos; //file snippet end position
int nthreadid; //thread's id
boolean bdownover = false; //downing is over
boolean bstop = false; //stop identical
fileaccessi fileaccessi = null; //file access interface
public filesplitterfetch(string surl,string sname,long nstart,long nend,int id) throws ioexception
{
this.surl = surl;
this.nstartpos = nstart;
this.nendpos = nend;
nthreadid = id;
fileaccessi = new fileaccessi(sname,nstartpos);//定位
}
public void run()
{
while(nstartpos < nendpos && !bstop)
{
try{
url url = new url(surl);
httpurlconnection httpconnection = (httpurlconnection)url.openconnection ();
httpconnection.setrequestproperty("user-agent","netfox");
string sproperty = "bytes="+nstartpos+"-";
httpconnection.setrequestproperty("range",sproperty);
utility.log(sproperty);
inputstream input = httpconnection.getinputstream();
//logresponsehead(httpconnection);
byte[] b = new byte[1024];
int nread;
while((nread=input.read(b,0,1024)) > 0 && nstartpos < nendpos && !bstop)
{
nstartpos += fileacces[iocblog.net 来源]
Tag: 断点续传
文章整理:iocblog
版权申明:本站文章均来自网络,如有侵权,请联系我们,我们收到后立即删除,谢谢!
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有。