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


Java ZipFile.setRunInThread方法代码示例

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


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

示例1: unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 解压文件到指定目录
 *
 * @param zipFile      压缩文件
 * @param outDir       输出路径
 * @param isClean      是否清理目录
 * @return
 */
public static boolean unzip(File zipFile, File outDir, boolean isClean){
    try {
        if(!FileHelper.exists(zipFile)){
            return false;
        }
        ZipFile zip = new ZipFile(zipFile);
        if(isClean && outDir.exists()){
            FileHelper.delete(outDir);
        }
        zip.setRunInThread(false);
        zip.extractAll(outDir.getPath());
        return true;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return false;
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:26,代码来源:ZipUtils.java

示例2: list

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
/**
 * 解压文件,注意该法方法并不是异步的
 *
 * @param zipFile      压缩文件
 * @param filter
 * @return
 */
public static void list(File zipFile, FileFilter filter){
    try {
        if(!FileHelper.exists(zipFile)){
            return;
        }
        ZipFile zip = new ZipFile(zipFile);
        zip.setRunInThread(false);

        // Get the list of file headers from the zip file
        List fileHeaderList = zip.getFileHeaders();

        // Loop through the file headers
        for (int i = 0; i < fileHeaderList.size(); i++) {
            // Extract the file to the specified destination
            filter.handle(zip, (FileHeader) fileHeaderList.get(i));
        }
    } catch (ZipException e) {
        e.printStackTrace();
    }
}
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:28,代码来源:ZipUtils.java

示例3: listForPattern

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static List<FileHeader> listForPattern(File zipFile, String regex){
        List<FileHeader> list = new ArrayList<>();
        Pattern p = Pattern.compile(regex);
//        Pattern p = Pattern.compile("[^/]*\\.dex");
        try {
            if(!FileHelper.exists(zipFile)){
                return new ArrayList<>(0);
            }
            ZipFile zip = new ZipFile( zipFile);
            zip.setRunInThread(false);

            // Get the list of file headers from the zip file
            List fileHeaderList = zip.getFileHeaders();

            // Loop through the file headers
            for (int i = 0; i < fileHeaderList.size(); i++) {
                // Extract the file to the specified destination
                FileHeader fileHeader = (FileHeader) fileHeaderList.get(i);
                Matcher matcher = p.matcher(fileHeader.getFileName());
                if(matcher.matches()){
                    list.add(fileHeader);
                }
            }
            return list;
        } catch (ZipException e) {
            e.printStackTrace();
        }
        return new ArrayList<>(0);
    }
 
开发者ID:linchaolong,项目名称:ApkToolPlus,代码行数:30,代码来源:ZipUtils.java

示例4: onCreateInternal

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
@Override
protected void onCreateInternal(Bundle savedInstanceState) {
    super.onCreateInternal(savedInstanceState);

    current = new File(getIntent().getData().getPath());

    try {
        zipFile = new ZipFile(current);
        zipFile.setRunInThread(true);
    } catch (ZipException e) {
        Log.d(TAG, "failed to open zip file " + current.getAbsolutePath(), e);
    }

    if (getIntent().hasExtra(EXTRA_PREFIX)) {
        toolbar.setTitle(FilenameUtils.getName(getIntent().getStringExtra(EXTRA_PREFIX)));
        toolbar.setSubtitle(current.getName());
    }

    passwordPrompt = new AlertDialog.Builder(this)
            .setView(R.layout.dialog_password)
            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    confirmFilePassword();
                }
            })
            .create();

    progressMonitor = zipFile.getProgressMonitor();

    progressDialog = new ProgressDialog(this);
    progressDialog.setMax(100);
    progressDialog.setCancelable(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
}
 
开发者ID:xingrz,项目名称:Finder,代码行数:36,代码来源:ZipFinderActivity.java

示例5: extractCompressedFile

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
protected void extractCompressedFile(File destinationDirectory, File compressedFile, Boolean deleteOnSuccess) {
  try {
    Util.log("Extracting %s to %s", compressedFile.getPath(), destinationDirectory.getPath());
    if (!compressedFile.exists()) {
      Util.log("[File not Found] Cannot find %s to extract", compressedFile.getPath());
      return;
    }
    if (!destinationDirectory.exists()) {
      Util.log("Creating directory %s", destinationDirectory.getPath());
      destinationDirectory.mkdirs();
    }
    ZipFile zipFile = new ZipFile(compressedFile);
    zipFile.setRunInThread(true);
    zipFile.extractAll(destinationDirectory.getAbsolutePath());
    ProgressMonitor monitor = zipFile.getProgressMonitor();
    while (monitor.getState() == ProgressMonitor.STATE_BUSY) {
      long totalProgress = monitor.getWorkCompleted() / monitor.getTotalWork();
      stateChanged(String.format("Extracting '%s'...", monitor.getFileName()), totalProgress);
    }
    File metainfDirectory = new File(destinationDirectory, "META-INF");
    if (metainfDirectory.exists()) {
      Util.removeDirectory(metainfDirectory);
    }
    stateChanged(String.format("Extracted '%s'", compressedFile.getPath()), 100f);
    if (monitor.getResult() == ProgressMonitor.RESULT_ERROR) {
      if (monitor.getException() != null) {
        monitor.getException().printStackTrace();
      } else {
        Util.log("An error occurred without any exception while extracting %s", compressedFile.getPath());
      }
    }
    Util.log("Extracted %s to %s", compressedFile.getPath(), destinationDirectory.getPath());
  } catch (ZipException e) {
    Util.log("An error occurred while extracting %s", compressedFile.getPath());
    e.printStackTrace();
  }
}
 
开发者ID:TechnicPack,项目名称:LegacyLauncher,代码行数:38,代码来源:GameUpdater.java

示例6: Unzip

import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public static void Unzip(final File zipFile, String dest, String passwd,
                         String charset, final Handler handler, final boolean isDeleteZipFile)throws Exception {
    ZipFile zFile = new ZipFile(zipFile);
    if (TextUtils.isEmpty(charset)) {
        charset = "UTF-8";
    }
    zFile.setFileNameCharset(charset);
    if (!zFile.isValidZipFile()) {
        throw new ZipException(
                "Compressed files are not illegal, may be damaged.");
    }
    File destDir = new File(dest); // Unzip directory
    if (destDir.isDirectory() && !destDir.exists()) {
        destDir.mkdir();
    }
    if (zFile.isEncrypted()) {
        zFile.setPassword(passwd.toCharArray());
    }

    final ProgressMonitor progressMonitor = zFile.getProgressMonitor();

    Thread progressThread = new Thread(new Runnable() {

        @Override
        public void run() {
            Bundle bundle = null;
            Message msg = null;
            try {
                int percentDone = 0;
                // long workCompleted=0;
                // handler.sendEmptyMessage(ProgressMonitor.RESULT_SUCCESS)
                if (handler == null) {
                    return;
                }
                handler.sendEmptyMessage(CompressStatus.START);
                while (true) {
                    Thread.sleep(1000);

                    percentDone = progressMonitor.getPercentDone();
                    bundle = new Bundle();
                    bundle.putInt(CompressKeys.PERCENT, percentDone);
                    msg = new Message();
                    msg.what = CompressStatus.HANDLING;
                    msg.setData(bundle);
                    handler.sendMessage(msg);
                    if (percentDone >= 100) {
                        break;
                    }
                }
                handler.sendEmptyMessage(CompressStatus.COMPLETED);
            } catch (InterruptedException e) {
                bundle = new Bundle();
                bundle.putString(CompressKeys.ERROR, e.getMessage());
                msg = new Message();
                msg.what = CompressStatus.ERROR;
                msg.setData(bundle);
                handler.sendMessage(msg);
                e.printStackTrace();
            } finally {
                if (isDeleteZipFile) {
                    zipFile.deleteOnExit();//zipFile.delete();
                }
            }
        }
    });

    progressThread.start();
    zFile.setRunInThread(true);
    zFile.extractAll(dest);
}
 
开发者ID:zapperbot,项目名称:Android_zip4j,代码行数:71,代码来源:Zip4jSp.java


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