當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。