forked from tome34/frameDemoMo2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
167 changed files
with
8,204 additions
and
470 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...fare/module_welfare/api/INetCallback.java → ...ase/net/common_callback/INetCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...src/main/java/com/example/tome/component_base/net/file_download/FileDownLoadCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.example.tome.component_base.net.file_download; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import okhttp3.ResponseBody; | ||
|
||
/** | ||
* 保存文件 | ||
*/ | ||
|
||
//public abstract class FileDownLoadCallback<T> { | ||
public class FileDownLoadCallback { | ||
|
||
|
||
private static File file; | ||
|
||
//可以重写,具体可由子类实现 | ||
public void onComplete() { | ||
} | ||
//下载成功的回调 | ||
//public abstract void onDownLoadSuccess(T t); | ||
//下载失败回调 | ||
// public abstract void onDownLoadFail(Throwable throwable); | ||
//下载进度监听 | ||
// public abstract void onProgress(int progress,long total); | ||
|
||
/** | ||
* 将文件写入本地 | ||
* @param responseBody 请求结果全体 | ||
* @param destFileDir 目标文件夹 | ||
* @param destFileName 目标文件名 | ||
* @return 写入完成的文件 | ||
* @throws IOException IO异常 | ||
*/ | ||
public static File saveFile(ResponseBody responseBody, String destFileDir, String destFileName) { | ||
InputStream is = null; | ||
byte[] buf = new byte[2048]; | ||
int len = 0; | ||
FileOutputStream fos = null; | ||
try { | ||
is = responseBody.byteStream(); | ||
final long total = responseBody.contentLength(); | ||
long sum = 0; | ||
|
||
File dir = new File(destFileDir); | ||
if (!dir.exists()) { | ||
dir.mkdirs(); | ||
} | ||
file = new File(dir, destFileName); | ||
fos = new FileOutputStream(file); | ||
while ((len = is.read(buf)) != -1) { | ||
sum += len; | ||
fos.write(buf, 0, len); | ||
final long finalSum = sum; | ||
//写入本地的进度条 | ||
// onProgress((int) (finalSum * 100 / total),total); | ||
} | ||
fos.flush(); | ||
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
try { | ||
if (is != null) is.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
try { | ||
if (fos != null) fos.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
return file; | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ | |
|
||
/** | ||
* @author liubp | ||
* 判断是否为空 | ||
*/ | ||
public class BasicTool { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.