本文整理匯總了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;
}
示例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();
}
}
示例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);
}
示例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);
}
示例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();
}
}
示例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);
}