表情解压使用新线程

This commit is contained in:
huangjian
2022-05-26 16:18:20 +08:00
parent c19b877200
commit f22c051e1e

View File

@@ -713,12 +713,12 @@ public class DynamicFaceModel extends BaseModel implements IDynamicFaceModel {
@Override @Override
public void onNext(ProgressInfo progressInfo) { public void onNext(ProgressInfo progressInfo) {
Logger.d("zip " + progressInfo.getProgress() + ""); //Logger.d("zip " + progressInfo.getProgress() + "");
} }
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Logger.d("zip " + "error"); //Logger.d("zip " + "error");
isRequestingZip = false; isRequestingZip = false;
} }
@@ -739,60 +739,63 @@ public class DynamicFaceModel extends BaseModel implements IDynamicFaceModel {
* @param faceListInfo-- * @param faceListInfo--
*/ */
private void unzipFaceZipFile(FaceListInfo faceListInfo) { private void unzipFaceZipFile(FaceListInfo faceListInfo) {
try { new Thread(() -> {
// 如果zip包不存在,或者说zip包的md5值不一样则返回 try {
if (!facesZipPath.exists() || faceListInfo == null || // 如果zip包不存在,或者说zip包的md5值不一样则返回
!faceListInfo.getZipMd5().equalsIgnoreCase(MD5Utils.getFileMD5String(facesZipPath))) { if (!facesZipPath.exists() || faceListInfo == null ||
return; !faceListInfo.getZipMd5().equalsIgnoreCase(MD5Utils.getFileMD5String(facesZipPath))) {
return;
}
} catch (Exception e) {
e.printStackTrace();
} }
} catch (Exception e) { long startTime = System.currentTimeMillis();
e.printStackTrace(); try {
} ZipInputStream zis = new ZipInputStream(new FileInputStream(facesZipPath));
long startTime = System.currentTimeMillis(); BufferedInputStream bis = new BufferedInputStream(zis);
try { //输出路径(文件夹目录)
ZipInputStream zis = new ZipInputStream(new FileInputStream(facesZipPath)); String parent = facesRootDir.getAbsolutePath() + "/" + faceListInfo.getVersion();
BufferedInputStream bis = new BufferedInputStream(zis); File file;
//输出路径(文件夹目录) ZipEntry entry;
String parent = facesRootDir.getAbsolutePath() + "/" + faceListInfo.getVersion(); while ((entry = zis.getNextEntry()) != null) {
File file; if (entry.isDirectory()) {
ZipEntry entry; // 如果有对应的路径名字的文件,则删除,重建一个目录
while ((entry = zis.getNextEntry()) != null) { file = new File(parent, entry.getName());
if (entry.isDirectory()) { if (file.exists() && file.isFile()) {
// 如果有对应的路径名字的文件,则删除,重建一个目录 boolean b = file.delete();
file = new File(parent, entry.getName()); if (b) {
if (file.exists() && file.isFile()) { file.mkdirs();
boolean b = file.delete(); }
if (b) {
file.mkdirs();
} }
continue;
} }
continue; file = new File(parent, entry.getName());
if (!file.exists()) {
(new File(file.getParent())).mkdirs();
} else if (file.exists() && file.isFile() && file.length() > 0) {
continue;
}
FileOutputStream out = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(out);
int b;
while ((b = bis.read()) != -1) {
bos.write(b);
}
bos.close();
out.close();
} }
file = new File(parent, entry.getName()); bis.close();
if (!file.exists()) { zis.close();
(new File(file.getParent())).mkdirs(); } catch (Exception e) {
} else if (file.exists() && file.isFile() && file.length() > 0) { e.printStackTrace();
continue;
}
FileOutputStream out = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(out);
int b;
while ((b = bis.read()) != -1) {
bos.write(b);
}
bos.close();
out.close();
} }
bis.close(); long endTime = System.currentTimeMillis();
zis.close(); LogUtils.d("unzipFaceZipFileTime="+(endTime-startTime));
} catch (Exception e) { // 更新对应的faceInfoList中的图片根目录
e.printStackTrace(); setPicRootDirectoryIntoFaceInfo(faceListInfo);
} // 如果有dialog.可以显示出对应的数据
long endTime = System.currentTimeMillis(); EventBus.getDefault().post(new FaceIsReadyEvent());
// 更新对应的faceInfoList中的图片根目录 }).start();
setPicRootDirectoryIntoFaceInfo(faceListInfo);
// 如果有dialog.可以显示出对应的数据
EventBus.getDefault().post(new FaceIsReadyEvent());
} }
private interface Api { private interface Api {