当前位置: 首页>>代码示例>>Java>>正文


Java SanitizedFile.delete方法代码示例

本文整理汇总了Java中org.fdroid.fdroid.data.SanitizedFile.delete方法的典型用法代码示例。如果您正苦于以下问题:Java SanitizedFile.delete方法的具体用法?Java SanitizedFile.delete怎么用?Java SanitizedFile.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.fdroid.fdroid.data.SanitizedFile的用法示例。


在下文中一共展示了SanitizedFile.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyApkToFiles

import org.fdroid.fdroid.data.SanitizedFile; //导入方法依赖的package包/类
/**
 * Copy an APK from {@param apkFile} to our internal files directory for 20 minutes.
 *
 * @param verifyHash If the file was just downloaded, then you should mark this as true and
 *                   request the file to be verified once it has finished copying. Otherwise,
 *                   if the app was installed from part of the system where it can't be tampered
 *                   with (e.g. installed apks on disk) then
 */
private static SanitizedFile copyApkToFiles(Context context, File apkFile, String destinationName,
                                            boolean verifyHash, String hash, String hashType)
        throws IOException {
    SanitizedFile sanitizedApkFile = new SanitizedFile(context.getFilesDir(), destinationName);

    // Don't think this is necessary, but the docs for FileUtils#copyFile() are not clear
    // on whether it overwrites destination files (pretty confident it does, as per the docs
    // in FileUtils#copyFileToDirectory() - which delegates to copyFile()).
    if (sanitizedApkFile.exists()) {
        sanitizedApkFile.delete();
    }

    FileUtils.copyFile(apkFile, sanitizedApkFile);

    // verify copied file's hash with expected hash from Apk class
    if (verifyHash && !Hasher.isFileMatchingHash(sanitizedApkFile, hash, hashType)) {
        FileUtils.deleteQuietly(apkFile);
        throw new IOException(apkFile + " failed to verify!");
    }

    // 20 minutes the start of the install process, delete the file
    final File apkToDelete = sanitizedApkFile;
    new Thread() {
        @Override
        public void run() {
            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_LOWEST);
            try {
                Thread.sleep(1200000);
            } catch (InterruptedException ignored) {
            } finally {
                FileUtils.deleteQuietly(apkToDelete);
            }
        }
    }.start();

    return sanitizedApkFile;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:46,代码来源:ApkCache.java


注:本文中的org.fdroid.fdroid.data.SanitizedFile.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。