本文整理汇总了Java中com.tencent.tinker.loader.shareutil.SharePatchFileUtil.verifyFileMd5方法的典型用法代码示例。如果您正苦于以下问题:Java SharePatchFileUtil.verifyFileMd5方法的具体用法?Java SharePatchFileUtil.verifyFileMd5怎么用?Java SharePatchFileUtil.verifyFileMd5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.tencent.tinker.loader.shareutil.SharePatchFileUtil
的用法示例。
在下文中一共展示了SharePatchFileUtil.verifyFileMd5方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extract
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public static boolean extract(ZipFile zipFile, ZipEntry entryFile, File extractTo, String targetMd5, boolean isDex) throws IOException {
int numAttempts = 0;
boolean isExtractionSuccessful = false;
while (numAttempts < MAX_EXTRACT_ATTEMPTS && !isExtractionSuccessful) {
numAttempts++;
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entryFile));
FileOutputStream fos = new FileOutputStream(extractTo);
BufferedOutputStream out = new BufferedOutputStream(fos);
TinkerLog.i(TAG, "try Extracting " + extractTo.getPath());
try {
byte[] buffer = new byte[ShareConstants.BUFFER_SIZE];
int length = bis.read(buffer);
while (length != -1) {
out.write(buffer, 0, length);
length = bis.read(buffer);
}
} finally {
SharePatchFileUtil.closeQuietly(out);
SharePatchFileUtil.closeQuietly(bis);
}
if (isDex) {
isExtractionSuccessful = SharePatchFileUtil.verifyDexFileMd5(extractTo, targetMd5);
} else {
isExtractionSuccessful = SharePatchFileUtil.verifyFileMd5(extractTo, targetMd5);
}
TinkerLog.i(TAG, "isExtractionSuccessful: %b", isExtractionSuccessful);
if (!isExtractionSuccessful) {
extractTo.delete();
if (extractTo.exists()) {
TinkerLog.e(TAG, "Failed to delete corrupted dex " + extractTo.getPath());
}
}
}
return isExtractionSuccessful;
}
示例2: loadLibraryFromTinker
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
* sample usage for native library
*
* @param context
* @param relativePath such as lib/armeabi
* @param libName for the lib libTest.so, you can pass Test or libTest, or libTest.so
* @return boolean
* @throws UnsatisfiedLinkError
*/
public static boolean loadLibraryFromTinker(Context context, String relativePath, String libName) throws UnsatisfiedLinkError {
final Tinker tinker = Tinker.with(context);
libName = libName.startsWith("lib") ? libName : "lib" + libName;
libName = libName.endsWith(".so") ? libName : libName + ".so";
String relativeLibPath = relativePath + "/" + libName;
//TODO we should add cpu abi, and the real path later
if (tinker.isEnabledForNativeLib() && tinker.isTinkerLoaded()) {
TinkerLoadResult loadResult = tinker.getTinkerLoadResultIfPresent();
if (loadResult.libs != null) {
for (String name : loadResult.libs.keySet()) {
if (name.equals(relativeLibPath)) {
String patchLibraryPath = loadResult.libraryDirectory + "/" + name;
File library = new File(patchLibraryPath);
if (library.exists()) {
//whether we check md5 when load
boolean verifyMd5 = tinker.isTinkerLoadVerify();
if (verifyMd5 && !SharePatchFileUtil.verifyFileMd5(library, loadResult.libs.get(name))) {
tinker.getLoadReporter().onLoadFileMd5Mismatch(library, ShareConstants.TYPE_LIBRARY);
} else {
System.load(patchLibraryPath);
TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath);
return true;
}
}
}
}
}
}
return false;
}
示例3: extract
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public static boolean extract(ZipFile zipFile, ZipEntry entryFile, File extractTo, String
targetMd5, boolean isDex) throws IOException {
int numAttempts = 0;
boolean isExtractionSuccessful = false;
while (numAttempts < 2 && !isExtractionSuccessful) {
numAttempts++;
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entryFile));
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(extractTo));
TinkerLog.i(TAG, "try Extracting " + extractTo.getPath(), new Object[0]);
try {
byte[] buffer = new byte[16384];
for (int length = bis.read(buffer); length != -1; length = bis.read(buffer)) {
out.write(buffer, 0, length);
}
if (isDex) {
isExtractionSuccessful = SharePatchFileUtil.verifyDexFileMd5(extractTo,
targetMd5);
} else {
isExtractionSuccessful = SharePatchFileUtil.verifyFileMd5(extractTo, targetMd5);
}
TinkerLog.i(TAG, "isExtractionSuccessful: %b", Boolean.valueOf
(isExtractionSuccessful));
if (!isExtractionSuccessful) {
extractTo.delete();
if (extractTo.exists()) {
TinkerLog.e(TAG, "Failed to delete corrupted dex " + extractTo.getPath(),
new Object[0]);
}
}
} finally {
SharePatchFileUtil.closeQuietly(out);
SharePatchFileUtil.closeQuietly(bis);
}
}
return isExtractionSuccessful;
}
示例4: loadLibraryFromTinker
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public static boolean loadLibraryFromTinker(Context context, String relativePath, String
libname) throws UnsatisfiedLinkError {
Tinker tinker = Tinker.with(context);
if (!libname.startsWith(ShareConstants.SO_PATH)) {
libname = ShareConstants.SO_PATH + libname;
}
if (!libname.endsWith(".so")) {
libname = libname + ".so";
}
String relativeLibPath = relativePath + "/" + libname;
if (tinker.isEnabledForNativeLib() && tinker.isTinkerLoaded()) {
TinkerLoadResult loadResult = tinker.getTinkerLoadResultIfPresent();
if (loadResult.libs != null) {
for (String name : loadResult.libs.keySet()) {
if (name.equals(relativeLibPath)) {
String patchLibraryPath = loadResult.libraryDirectory + "/" + name;
File library = new File(patchLibraryPath);
if (!library.exists()) {
continue;
} else if (!tinker.isTinkerLoadVerify() || SharePatchFileUtil
.verifyFileMd5(library, (String) loadResult.libs.get(name))) {
System.load(patchLibraryPath);
TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath,
new Object[0]);
return true;
} else {
tinker.getLoadReporter().onLoadFileMd5Mismatch(library, 6);
}
}
}
}
}
return false;
}
示例5: loadLibraryFromTinker
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
* you can use these api to load tinker library without tinker is installed!
* same as {@code TinkerInstaller#loadLibraryFromTinker}
*
* @param applicationLike
* @param relativePath
* @param libname
* @return
* @throws UnsatisfiedLinkError
*/
public static boolean loadLibraryFromTinker(ApplicationLike applicationLike, String relativePath, String libname) throws UnsatisfiedLinkError {
libname = libname.startsWith("lib") ? libname : "lib" + libname;
libname = libname.endsWith(".so") ? libname : libname + ".so";
String relativeLibPath = relativePath + "/" + libname;
//TODO we should add cpu abi, and the real path later
if (TinkerApplicationHelper.isTinkerEnableForNativeLib(applicationLike)
&& TinkerApplicationHelper.isTinkerLoadSuccess(applicationLike)) {
HashMap<String, String> loadLibraries = TinkerApplicationHelper.getLoadLibraryAndMd5(applicationLike);
if (loadLibraries != null) {
String currentVersion = TinkerApplicationHelper.getCurrentVersion(applicationLike);
if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
return false;
}
File patchDirectory = SharePatchFileUtil.getPatchDirectory(applicationLike.getApplication());
if (patchDirectory == null) {
return false;
}
File patchVersionDirectory = new File(patchDirectory.getAbsolutePath() + "/" + SharePatchFileUtil.getPatchVersionDirectory(currentVersion));
String libPrePath = patchVersionDirectory.getAbsolutePath() + "/" + ShareConstants.SO_PATH;
for (String name : loadLibraries.keySet()) {
if (name.equals(relativeLibPath)) {
String patchLibraryPath = libPrePath + "/" + name;
File library = new File(patchLibraryPath);
if (library.exists()) {
//whether we check md5 when load
boolean verifyMd5 = applicationLike.getTinkerLoadVerifyFlag();
if (verifyMd5 && !SharePatchFileUtil.verifyFileMd5(library, loadLibraries.get(name))) {
//do not report, because tinker is not install
TinkerLog.i(TAG, "loadLibraryFromTinker md5mismatch fail:" + patchLibraryPath);
} else {
System.load(patchLibraryPath);
TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath);
return true;
}
}
}
}
}
}
return false;
}
示例6: loadLibraryFromTinker
import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public static boolean loadLibraryFromTinker(ApplicationLike applicationLike, String
relativePath, String libname) throws UnsatisfiedLinkError {
if (!libname.startsWith(ShareConstants.SO_PATH)) {
libname = ShareConstants.SO_PATH + libname;
}
if (!libname.endsWith(".so")) {
libname = libname + ".so";
}
String relativeLibPath = relativePath + "/" + libname;
if (isTinkerEnableForNativeLib(applicationLike) && isTinkerLoadSuccess(applicationLike)) {
HashMap<String, String> loadLibraries = getLoadLibraryAndMd5(applicationLike);
if (loadLibraries != null) {
String currentVersion = getCurrentVersion(applicationLike);
if (ShareTinkerInternals.isNullOrNil(currentVersion)) {
return false;
}
File patchDirectory = SharePatchFileUtil.getPatchDirectory(applicationLike
.getApplication());
if (patchDirectory == null) {
return false;
}
String libPrePath = new File(patchDirectory.getAbsolutePath() + "/" +
SharePatchFileUtil.getPatchVersionDirectory(currentVersion))
.getAbsolutePath() + "/" + ShareConstants.SO_PATH;
for (String name : loadLibraries.keySet()) {
if (name.equals(relativeLibPath)) {
String patchLibraryPath = libPrePath + "/" + name;
File library = new File(patchLibraryPath);
if (!library.exists()) {
continue;
} else if (!applicationLike.getTinkerLoadVerifyFlag() ||
SharePatchFileUtil.verifyFileMd5(library, (String) loadLibraries
.get(name))) {
System.load(patchLibraryPath);
TinkerLog.i(TAG, "loadLibraryFromTinker success:" + patchLibraryPath,
new Object[0]);
return true;
} else {
TinkerLog.i(TAG, "loadLibraryFromTinker md5mismatch fail:" +
patchLibraryPath, new Object[0]);
}
}
}
}
}
return false;
}