ReRxMvpGreenDao 斷點續傳

2021-08-11 05:09:04 字數 3999 閱讀 8463

retrofit:

public inte***ce retrofitzj

public class retrofitapi 

}

bean:

@entity

public class bean

daomanager:

public class dbmanager 

public static dbmanager getinstance(context context)

// 資料庫物件

// 資料庫物件

daomaster.devopenhelper devopenhelper = new daomaster.devopenhelper(mcontext, "student.db", null);

daomaster daomaster = new daomaster(devopenhelper.getwritabledb());

daosession daosession = daomaster.newsession();

instance.beandao = daosession.getbeandao();

}return instance;

}/** 新增資料 */

public void addtocityinfotable(bean item)

/** 查詢 */

/** 通過城市id查詢其型別id */

public listgetcityinfolist(int threadnum)

public void updateinfo(int id,long rang)

}

model介面:

public inte***ce idownloadmodel 

void stop();

void jixu();

void getprogress();

}

model實現類:

public class downloadmodel implements idownloadmodel 

@override

public void getdata(string start, string url, final string url2, final getcallback callback)

@override

public void onerror(throwable e)

@override

public void onnext(responsebody responsebody)

});}

@override

public void stop()

@override

public void jixu()

@override

public void getprogress()

public void downloadfile(long length, string url2) catch (exception e)

}int threadnum = 5;

long blocksize = length / threadnum;

long startposition = 0;

long end = 0;

// //四捨五入--- 讓乙個數字+0。5在四捨五入 就變成 向上取整

for (int i = 0; i < threadnum; i++) else

end = startposition + blocksize - 1;

bean bean2 = new bean();

bean2.setthreadnum(i + "");

bean2.setrange((long) 0);

bean2.setstart(startposition);

bean2.setend(end);

dbmanager.getinstance(context).addtocityinfotable(bean2);

}downloadtask(startposition, file, end, length, i);}}

public void downloadtask(final long startposition, final file file, long end, final long length, final int i)

@override

public void onerror(throwable e)

@override

public void onnext(responsebody responsebody) else if (statedownload == download_pause)

}} catch (exception e) finally catch (exception e)

}if (raf != null) catch (exception e) }}

}});

}public void setgetprogress(downloadmodel.getprogress getprogress)

public inte***ce getprogress

private long downloadedsize = 0;

@suppresslint("handlerleak")

handler handler = new handler()

getprogress.getprogress_length(downloadedsize * 100 / l);

log.i("downloadedsize", "handlemessage: " + downloadedsize);

log.i("百分比", "handlemessage: " + downloadedsize * 100 / l);}};

}

view介面:

public inte***ce idownloadview

presenter:

public class downloadpresenter implements basepresenter

public void down(final string start, final string url, final string url2)

});}

public void stop()

public void jixu()

public void setprogress()

});}

@override

public void atteach(idownloadview view)

@override

public void deatch()

}

activity:

public class mainactivity extends baseactivityimplements idownloadview, view.onclicklistener 

@override

public void createpresenter()

private void initview()

@override

public void onclick(view v)

}@override

public void getdata(responsebody responsebody)

@override

public void getpro(long length)

}

布局:

scrapy 斷點續爬

第一步 安裝berkeleydb資料庫 第二部 pip install bsddb3 第三部 pip install scrapy deltafetch 第四部 settings.py設定 spider middlewares deltafetch enabled true deltafetch e...

http range實現斷點續傳(斷點續載)

使用http range實現斷點續傳 伺服器端 響應的格式是 記錄檔案大小 long pastlength 0 int rangeswitch 0 long tolength 0 long contentlength 0 客戶端請求的位元組總量 string rangebytes 記錄客戶端傳來的形...

用HttpListener實現檔案斷點續傳

普通方式請求伺服器上的乙個文時,所發出的請求和接受到的伺服器如下 request header cache control no cache connection close pragma no cache accept host localhost response header 當伺服器支援斷點...