当前位置: 首页 > wzjs >正文

如何快速搭建个人网站知了seo

如何快速搭建个人网站,知了seo,太原网站建设方案书,jsp做物流网站一、背景 根据后端返回的url下载地址,去执行文件下载,将文件保存到SD卡。这里使用Retrofit网络框架。 二、代码实现 2.1、定义一个DownloadFileService interface DownloadFileService {StreamingGETsuspend fun downloadFile(Url fileUrl: String):ResponseBody…

一、背景

根据后端返回的url下载地址,去执行文件下载,将文件保存到SD卡。这里使用Retrofit网络框架。

二、代码实现

2.1、定义一个DownloadFileService
interface DownloadFileService {@Streaming@GETsuspend fun downloadFile(@Url fileUrl: String):ResponseBody
}
2.2、定义一个FileDownloadClient
private var mDownliadService: DownloadFileService? = nullfun getUploadFileService() :DownloadFileService{if(mDownliadService==null){val okHttpClient = OkHttpClient.Builder().callTimeout(0, TimeUnit.SECONDS)//0 代表不考虑请求的超时 这里的超时是指整个请求过程的超时,如果设置太短,任务还没执行完,会以超时结束任务,这里尤其要注意.connectTimeout(60, TimeUnit.SECONDS).readTimeout(60, TimeUnit.SECONDS).writeTimeout(60, TimeUnit.SECONDS).retryOnConnectionFailure(false)// 重连.followRedirects(false)// 重定向//.addInterceptor(RequestInterceptor(authorization,requestId,offset,uploadType))//.addInterceptor(RemoveContentLengthInterceptor())//.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build()val retrofit: Retrofit = Retrofit.Builder().baseUrl(DeviceUtil.getInstance().getServerIp()).addConverterFactory(GsonConverterFactory.create()).client(okHttpClient).build()mDownliadService= retrofit.create(DownloadFileService::class.java)}return mDownliadService!!}
2.3、定义一个DownloadCallback
interface DownloadCallback {fun onSuccess(srcApkTarPath:String)fun onProgress(progress: Int)fun onFailure(msg:String?)
}
2.4、定义一个FileDownloadManager,执行文件下载
class FileDownloadManager {private val TAG = "FileDownloadManager_"companion object {private var singleInstance: FileDownloadManager? = nullget() {// 懒汉模式if (null == field) {field = FileDownloadManager()}return field}@Synchronized // 添加注解,线程同步,线程安全fun getInstance(): FileDownloadManager {return singleInstance!! // 表示非空时执行}}fun doDownloadFile(appName:String,packageName: String,downUrl: String,fileSize: Long,fileMd5:String,downloadCallback: DownloadCallback) {try {val coroutineScope = CoroutineScope(Dispatchers.Default)coroutineScope.launch(Dispatchers.IO) {val response = FileDownloadClient.getUploadFileService().downloadFile(downUrl)val length = response.contentLength()XLogUtil.d("${TAG}doDownloadFile result appName:$appName,,,packageName:$packageName,,,length:$length,,,fileSize:$fileSize,,,downUrl:$downUrl")if (length > 0) {val folder = File(ConstantUtil.DOWNLOAD_FOLDER_PATH)if (!folder.exists()) {folder.mkdirs()}// 使用输入流保存响应体到文件val inputStream = response.byteStream()val fileName = "$packageName.tar"var fileTargetPath =ConstantUtil.DOWNLOAD_FOLDER_PATH + File.separator + fileNameval outputStream = FileOutputStream(fileTargetPath)val buf = ByteArray(1024)var downLoadFileSize = 0var lastProgress = 0do {val numread = inputStream.read(buf)if (numread == -1) {break}outputStream.write(buf, 0, numread)downLoadFileSize += numreadval progressValue =((downLoadFileSize * 100f) / length).toInt()//相同的进度值只回调一次if (progressValue > lastProgress) {lastProgress = progressValuedownloadCallback?.apply {onProgress(progressValue)}}} while (true)outputStream.flush()// 关闭文件输出流和输入流outputStream.close()//inputStream.close()val localFileMd5=FileUtil.getInstance().getFileMd5(fileTargetPath)if(localFileMd5==fileMd5){downloadCallback?.onSuccess(fileTargetPath)}else{downloadCallback?.onFailure("文件 md5 不一致,localFileMd5:$localFileMd5,,,fileMd5:$fileMd5")}}else{downloadCallback?.onFailure("读取文件len=0")}}} catch (e: Exception) {XLogUtil.e("${TAG}doDownloadFile Exception appName:$appName,,,packageName:$packageName,,,Exception:${e.message},,,fileSize:$fileSize,,,downUrl:$downUrl")downloadCallback?.onFailure(e.message)}}
}

http://www.dtcms.com/wzjs/403497.html

相关文章:

  • 购物网站用模板好不好广告推广一个月多少钱
  • 供应商管理制度怎么快速优化网站
  • 网站横幅背景图免费b站推广短视频
  • 外贸建站是什么意思seo基础教程视频
  • 福州网站制西安百度代运营
  • 做网站的标签及属性微信小程序开发零基础入门
  • 北海市高德小学简介网站关键词优化的步骤和过程
  • 网站建设责任书seo少女
  • 泰安高端网站建设报价哪里有学市场营销培训班
  • 旅游网站建设与规划网站排名推广软件
  • 基层建设收录网站查数据的网站有哪些
  • 开发施工建设网站审核百度网站排名怎么提高
  • 自己做的网站和ie不兼容微信群二维码推广平台
  • 唐山网站制作价格附近有没有学电脑培训的
  • 青岛网站建设工作室软文范文大全1000字
  • 西安网站推广招聘关键词排名优化公司哪家强
  • 廊坊商昊网站建设最近最新的新闻
  • 网站 尺寸seo顾问
  • 呼和浩特企业网站建设app拉新推广平台
  • 桥头仿做网站太原最新情况
  • 做网站人员工资樱桃bt官网
  • 做淘宝那样的网站长沙网站推广工具
  • chatgpt 网站学开网店哪个培训机构好正规
  • 天津建设交培训中心网站北京推广优化公司
  • 网站的布局怎么做链接点击量软件
  • 学习建站的网站网站建设免费网站
  • 网站运作流程北京网站seo哪家公司好
  • 网站是什么公司做的seo矩阵培训
  • 广州网站建设哪家好谷歌竞价排名推广公司
  • 自己做链接的网站吗网站策划是干什么的