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


Java SharePatchFileUtil.closeQuietly方法代码示例

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


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

示例1: extractDexToJar

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
private static void extractDexToJar(File dex) throws IOException {
    FileOutputStream fos = new FileOutputStream(dex + ".jar");
    InputStream in = new FileInputStream(dex);

    ZipOutputStream zos = null;
    BufferedInputStream bis = null;

    try {
        zos = new ZipOutputStream(new
                BufferedOutputStream(fos));
        bis = new BufferedInputStream(in);

        byte[] buffer = new byte[ShareConstants.BUFFER_SIZE];
        ZipEntry entry = new ZipEntry(ShareConstants.DEX_IN_JAR);
        zos.putNextEntry(entry);
        int length = bis.read(buffer);
        while (length != -1) {
            zos.write(buffer, 0, length);
            length = bis.read(buffer);
        }
        zos.closeEntry();
    } finally {
        SharePatchFileUtil.closeQuietly(bis);
        SharePatchFileUtil.closeQuietly(zos);
    }
}
 
开发者ID:baidao,项目名称:tinker-manager,代码行数:27,代码来源:SampleUpgradePatch.java

示例2: readVersionProperty

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
private void readVersionProperty() {
    if (versionFile == null || !versionFile.exists() || versionFile.length() == 0) {
        return;
    }

    Properties properties = new Properties();
    FileInputStream inputStream = null;
    try {
        inputStream = new FileInputStream(versionFile);
        properties.load(inputStream);
        uuid = properties.getProperty(UUID_VALUE);
        appVersion = properties.getProperty(APP_VERSION);
        grayValue = ServerUtils.stringToInteger(properties.getProperty(GRAY_VALUE));
        patchVersion = ServerUtils.stringToInteger(properties.getProperty(CURRENT_VERSION));
        patchMd5 = properties.getProperty(CURRENT_MD5);
    } catch (IOException e) {
        TinkerLog.e(TAG, "readVersionProperty exception:" + e);
    } finally {
        SharePatchFileUtil.closeQuietly(inputStream);
    }

}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:23,代码来源:VersionUtils.java

示例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 < 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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:41,代码来源:BasePatchInternal.java

示例4: 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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:37,代码来源:BasePatchInternal.java

示例5: run

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
@Override
public void run() {
    InputStream inputStream = null;
    try {
        HttpURLConnection conn = (HttpURLConnection) url.toURL().openConnection();
        conn.setRequestMethod(url.getMethod());
        conn.setDoOutput(true);
        conn.setReadTimeout(10000 /* milliseconds */);
        conn.setConnectTimeout(15000 /* milliseconds */);
        conn.setInstanceFollowRedirects(false);
        conn.setUseCaches(false);
        for (Map.Entry<String, String> entry : url.getHeaders().entrySet()) {
            conn.setRequestProperty(entry.getKey(), entry.getValue());
        }
        switch (url.getMethod()) {
            case "GET":
                break;
            case "POST":
                OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream(), ServerUtils.CHARSET);
                writer.write(url.getBody());
                writer.flush();
                writer.close();
                break;
            default:
                throw new RuntimeException("Unsupported request method" + url.getMethod());
        }
        conn.connect();
        TinkerLog.d(TAG, "response code " + conn.getResponseCode() + " msg: " + conn.getResponseMessage());
        inputStream = conn.getInputStream();
        this.callback.onDataReady(inputStream);
    } catch (IOException e) {
        e.printStackTrace();
        this.callback.onLoadFailed(e);
    } finally {
        SharePatchFileUtil.closeQuietly(inputStream);
    }
}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:38,代码来源:UrlConnectionStreamFetcher.java

示例6: updateVersionProperty

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
public void updateVersionProperty(String appVersion, int currentVersion,
                                  String patchMd5, int grayValue, String uuid) {
    TinkerLog.d(TAG, "updateVersionProperty file path:"
        + versionFile.getAbsolutePath()
        + " , appVersion: " + appVersion
        + " , patchVersion:" + currentVersion
        + " , patchMd5:" + patchMd5
        + " , grayValue:" + grayValue
        + " , uuid:" + uuid);

    File parentFile = versionFile.getParentFile();
    if (!parentFile.exists() && !parentFile.mkdirs()) {
        throw new TinkerRuntimeException("make mkdirs error: " + parentFile.getAbsolutePath());
    }

    Properties newProperties = new Properties();
    newProperties.put(CURRENT_VERSION, String.valueOf(currentVersion));
    newProperties.put(CURRENT_MD5, patchMd5);

    newProperties.put(GRAY_VALUE, String.valueOf(grayValue));
    newProperties.put(APP_VERSION, appVersion);
    newProperties.put(UUID_VALUE, uuid);
    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(versionFile, false);
        String comment = "from old version:" + getPatchVersion() + " to new version:" + currentVersion;
        newProperties.store(outputStream, comment);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        SharePatchFileUtil.closeQuietly(outputStream);
    }
    //update value
    this.appVersion = appVersion;
    this.patchVersion = currentVersion;
    this.grayValue = grayValue;
    this.uuid = uuid;
    this.patchMd5 = patchMd5;
}
 
开发者ID:TinkerPatch,项目名称:tinkerpatch-sdk,代码行数:40,代码来源:VersionUtils.java

示例7: extractDexToJar

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
private static boolean extractDexToJar(ZipFile zipFile, ZipEntry entryFile, File extractTo,
                                       String targetMd5) throws IOException {
    Throwable th;
    int numAttempts = 0;
    boolean isExtractionSuccessful = false;
    while (numAttempts < 2 && !isExtractionSuccessful) {
        numAttempts++;
        FileOutputStream fos = new FileOutputStream(extractTo);
        InputStream in = zipFile.getInputStream(entryFile);
        ZipOutputStream zos = null;
        BufferedInputStream bis = null;
        TinkerLog.i(TAG, "try Extracting " + extractTo.getPath(), new Object[0]);
        try {
            ZipOutputStream zos2 = new ZipOutputStream(new BufferedOutputStream(fos));
            try {
                BufferedInputStream bis2 = new BufferedInputStream(in);
                try {
                    byte[] buffer = new byte[16384];
                    zos2.putNextEntry(new ZipEntry("classes.dex"));
                    for (int length = bis2.read(buffer); length != -1; length = bis2.read
                            (buffer)) {
                        zos2.write(buffer, 0, length);
                    }
                    zos2.closeEntry();
                    SharePatchFileUtil.closeQuietly(bis2);
                    SharePatchFileUtil.closeQuietly(zos2);
                    isExtractionSuccessful = SharePatchFileUtil.verifyDexFileMd5(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]);
                        }
                    }
                } catch (Throwable th2) {
                    th = th2;
                    bis = bis2;
                    zos = zos2;
                }
            } catch (Throwable th3) {
                th = th3;
                zos = zos2;
            }
        } catch (Throwable th4) {
            th = th4;
        }
    }
    return isExtractionSuccessful;
    SharePatchFileUtil.closeQuietly(bis);
    SharePatchFileUtil.closeQuietly(zos);
    throw th;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:56,代码来源:DexDiffPatchInternal.java

示例8: readRetryProperty

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
static RetryInfo readRetryProperty(File infoFile) {
    IOException e;
    Throwable th;
    String md5 = null;
    String times = null;
    Properties properties = new Properties();
    FileInputStream inputStream = null;
    try {
        FileInputStream inputStream2 = new FileInputStream(infoFile);
        try {
            properties.load(inputStream2);
            md5 = properties.getProperty(UpgradePatchRetry.RETRY_FILE_MD5_PROPERTY);
            times = properties.getProperty(UpgradePatchRetry.RETRY_COUNT_PROPERTY);
            SharePatchFileUtil.closeQuietly(inputStream2);
            inputStream = inputStream2;
        } catch (IOException e2) {
            e = e2;
            inputStream = inputStream2;
            try {
                e.printStackTrace();
                SharePatchFileUtil.closeQuietly(inputStream);
                return new RetryInfo(md5, times);
            } catch (Throwable th2) {
                th = th2;
                SharePatchFileUtil.closeQuietly(inputStream);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            inputStream = inputStream2;
            SharePatchFileUtil.closeQuietly(inputStream);
            throw th;
        }
    } catch (IOException e3) {
        e = e3;
        e.printStackTrace();
        SharePatchFileUtil.closeQuietly(inputStream);
        return new RetryInfo(md5, times);
    }
    return new RetryInfo(md5, times);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:42,代码来源:UpgradePatchRetry.java

示例9: writeRetryProperty

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
static void writeRetryProperty(File infoFile, RetryInfo info) {
    Exception e;
    Throwable th;
    if (info != null) {
        File parentFile = infoFile.getParentFile();
        if (!parentFile.exists()) {
            parentFile.mkdirs();
        }
        Properties newProperties = new Properties();
        newProperties.put(UpgradePatchRetry.RETRY_FILE_MD5_PROPERTY, info.md5);
        newProperties.put(UpgradePatchRetry.RETRY_COUNT_PROPERTY, info.times);
        FileOutputStream outputStream = null;
        try {
            FileOutputStream outputStream2 = new FileOutputStream(infoFile, false);
            try {
                newProperties.store(outputStream2, null);
                SharePatchFileUtil.closeQuietly(outputStream2);
                outputStream = outputStream2;
            } catch (Exception e2) {
                e = e2;
                outputStream = outputStream2;
                try {
                    TinkerLog.printErrStackTrace(UpgradePatchRetry.TAG, e, "retry write " +
                            "property fail", new Object[0]);
                    SharePatchFileUtil.closeQuietly(outputStream);
                } catch (Throwable th2) {
                    th = th2;
                    SharePatchFileUtil.closeQuietly(outputStream);
                    throw th;
                }
            } catch (Throwable th3) {
                th = th3;
                outputStream = outputStream2;
                SharePatchFileUtil.closeQuietly(outputStream);
                throw th;
            }
        } catch (Exception e3) {
            e = e3;
            TinkerLog.printErrStackTrace(UpgradePatchRetry.TAG, e, "retry write property " +
                    "fail", new Object[0]);
            SharePatchFileUtil.closeQuietly(outputStream);
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:45,代码来源:UpgradePatchRetry.java

示例10: extractDexToJar

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
 * repack dex to jar
 *
 * @param zipFile
 * @param entryFile
 * @param extractTo
 * @param targetMd5
 * @return boolean
 * @throws IOException
 */
private static boolean extractDexToJar(ZipFile zipFile, ZipEntry entryFile, File extractTo, String targetMd5) throws IOException {
    int numAttempts = 0;
    boolean isExtractionSuccessful = false;
    while (numAttempts < MAX_EXTRACT_ATTEMPTS && !isExtractionSuccessful) {
        numAttempts++;

        FileOutputStream fos = new FileOutputStream(extractTo);
        InputStream in = zipFile.getInputStream(entryFile);

        ZipOutputStream zos = null;
        BufferedInputStream bis = null;

        TinkerLog.i(TAG, "try Extracting " + extractTo.getPath());
        try {
            zos = new ZipOutputStream(new
                    BufferedOutputStream(fos));
            bis = new BufferedInputStream(in);

            byte[] buffer = new byte[ShareConstants.BUFFER_SIZE];
            ZipEntry entry = new ZipEntry(ShareConstants.DEX_IN_JAR);
            zos.putNextEntry(entry);
            int length = bis.read(buffer);
            while (length != -1) {
                zos.write(buffer, 0, length);
                length = bis.read(buffer);
            }
            zos.closeEntry();
        } finally {
            SharePatchFileUtil.closeQuietly(bis);
            SharePatchFileUtil.closeQuietly(zos);
        }

        isExtractionSuccessful = SharePatchFileUtil.verifyDexFileMd5(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;
}
 
开发者ID:baidao,项目名称:tinker-manager,代码行数:55,代码来源:SampleDexDiffPatchInternal.java

示例11: patchDexFile

import com.tencent.tinker.loader.shareutil.SharePatchFileUtil; //导入方法依赖的package包/类
/**
 * Generate patched dex file (May wrapped it by a jar if needed.)
 * @param baseApk
 *   OldApk.
 * @param patchPkg
 *   Patch package, it is also a zip file.
 * @param oldDexEntry
 *   ZipEntry of old dex.
 * @param patchFileEntry
 *   ZipEntry of patch file. (also ends with .dex) This could be null.
 * @param patchInfo
 *   Parsed patch info from package-meta.txt
 * @param patchedDexFile
 *   Patched dex file, may be a jar.
 *
 * <b>Notice: patchFileEntry and smallPatchInfoFile cannot both be null.</b>
 *
 * @throws IOException
 */
private static void patchDexFile(
        ZipFile baseApk, ZipFile patchPkg, ZipEntry oldDexEntry, ZipEntry patchFileEntry,
        ShareDexDiffPatchInfo patchInfo,  File patchedDexFile) throws IOException {
    InputStream oldDexStream = null;
    InputStream patchFileStream = null;
    try {
        oldDexStream = new BufferedInputStream(baseApk.getInputStream(oldDexEntry));
        patchFileStream = (patchFileEntry != null ? new BufferedInputStream(patchPkg.getInputStream(patchFileEntry)) : null);

        final boolean isRawDexFile = SharePatchFileUtil.isRawDexFile(patchInfo.rawName);
        if (!isRawDexFile || patchInfo.isJarMode) {
            ZipOutputStream zos = null;
            try {
                zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(patchedDexFile)));
                zos.putNextEntry(new ZipEntry(ShareConstants.DEX_IN_JAR));
                // Old dex is not a raw dex file.
                if (!isRawDexFile) {
                    ZipInputStream zis = null;
                    try {
                        zis = new ZipInputStream(oldDexStream);
                        ZipEntry entry;
                        while ((entry = zis.getNextEntry()) != null) {
                            if (ShareConstants.DEX_IN_JAR.equals(entry.getName())) break;
                        }
                        if (entry == null) {
                            throw new TinkerRuntimeException("can't recognize zip dex format file:" + patchedDexFile.getAbsolutePath());
                        }
                        new DexPatchApplier(zis, patchFileStream).executeAndSaveTo(zos);
                    } finally {
                        SharePatchFileUtil.closeQuietly(zis);
                    }
                } else {
                    new DexPatchApplier(oldDexStream, patchFileStream).executeAndSaveTo(zos);
                }
                zos.closeEntry();
            } finally {
                SharePatchFileUtil.closeQuietly(zos);
            }
        } else {
            new DexPatchApplier(oldDexStream, patchFileStream).executeAndSaveTo(patchedDexFile);
        }
    } finally {
        SharePatchFileUtil.closeQuietly(oldDexStream);
        SharePatchFileUtil.closeQuietly(patchFileStream);
    }
}
 
开发者ID:baidao,项目名称:tinker-manager,代码行数:66,代码来源:SampleDexDiffPatchInternal.java


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