本文整理汇总了Java中net.lingala.zip4j.progress.ProgressMonitor类的典型用法代码示例。如果您正苦于以下问题:Java ProgressMonitor类的具体用法?Java ProgressMonitor怎么用?Java ProgressMonitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProgressMonitor类属于net.lingala.zip4j.progress包,在下文中一共展示了ProgressMonitor类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractFile
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Extracts file to the specified directory using any
* user defined parameters in UnzipParameters. Output file name
* will be overwritten with the value in newFileName. If this
* parameter is null, then file name will be the same as in
* FileHeader.getFileName
* @param zipModel
* @param outPath
* @param unzipParameters
* @throws ZipException
*/
public void extractFile(ZipModel zipModel, String outPath,
UnzipParameters unzipParameters, String newFileName,
ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
if (zipModel == null) {
throw new ZipException("input zipModel is null");
}
if (!Zip4jUtil.checkOutputFolder(outPath)) {
throw new ZipException("Invalid output path");
}
if (this == null) {
throw new ZipException("invalid file header");
}
Unzip unzip = new Unzip(zipModel);
unzip.extractFile(this, outPath, unzipParameters, newFileName, progressMonitor, runInThread);
}
示例2: removeZipFile
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public HashMap removeZipFile(final ZipModel zipModel,
final FileHeader fileHeader, final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
if (runInThread) {
Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
public void run() {
try {
initRemoveZipFile(zipModel, fileHeader, progressMonitor);
progressMonitor.endProgressMonitorSuccess();
} catch (ZipException e) {
}
}
};
thread.start();
return null;
} else {
HashMap retMap = initRemoveZipFile(zipModel, fileHeader, progressMonitor);
progressMonitor.endProgressMonitorSuccess();
return retMap;
}
}
示例3: mergeSplitZipFiles
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Merges split Zip files into a single Zip file
* @param zipModel
* @throws ZipException
*/
public void mergeSplitZipFiles(final ZipModel zipModel, final File outputZipFile,
final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
if (runInThread) {
Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
public void run() {
try {
initMergeSplitZipFile(zipModel, outputZipFile, progressMonitor);
} catch (ZipException e) {
}
}
};
thread.start();
} else {
initMergeSplitZipFile(zipModel, outputZipFile, progressMonitor);
}
}
示例4: extractFile
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Extracts a specific file from the zip file to the destination path.
* If destination path is invalid, then this method throws an exception.
* @param fileHeader
* @param destPath
* @param unzipParameters
* @param newFileName
* @throws ZipException
*/
public void extractFile(FileHeader fileHeader, String destPath,
UnzipParameters unzipParameters, String newFileName) throws ZipException {
if (fileHeader == null) {
throw new ZipException("input file header is null, cannot extract file");
}
if (!Zip4jUtil.isStringNotNullAndNotEmpty(destPath)) {
throw new ZipException("destination path is empty or null, cannot extract file");
}
readZipInfo();
if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}
fileHeader.extractFile(zipModel, destPath, unzipParameters, newFileName, progressMonitor, runInThread);
}
示例5: run
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
@Override
public void run() {
if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
progressDialog.setProgress(progressMonitor.getPercentDone());
handler.postDelayed(this, PROGRESS_INTERVAL);
} else if (progressMonitor.getResult() == ProgressMonitor.RESULT_SUCCESS) {
progressDialog.dismiss();
startActivityForResult(pendingIntent, REQUEST_OPEN_FILE);
overridePendingTransitionForBuiltInViewer(pendingIntent);
extracting = null;
} else if (progressMonitor.getResult() == ProgressMonitor.RESULT_ERROR) {
progressDialog.dismiss();
Log.e(TAG, "failed to extract file " + extracting.getFileName(), progressMonitor.getException());
Toast.makeText(this, "密码错误", Toast.LENGTH_SHORT).show();
extracting.setPassword(null);
extracting = null;
}
}
示例6: addFiles
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public void addFiles(final ArrayList fileList, final ZipParameters parameters,
final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
if (fileList == null || parameters == null) {
throw new ZipException("one of the input parameters is null when adding files");
}
if(fileList.size() <= 0) {
throw new ZipException("no files to add");
}
progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_ADD);
progressMonitor.setState(ProgressMonitor.STATE_BUSY);
progressMonitor.setResult(ProgressMonitor.RESULT_WORKING);
if (runInThread) {
progressMonitor.setTotalWork(calculateTotalWork(fileList, parameters));
progressMonitor.setFileName(((File)fileList.get(0)).getAbsolutePath());
Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
public void run() {
try {
initAddFiles(fileList, parameters, progressMonitor);
} catch (ZipException e) {
}
}
};
thread.start();
} else {
initAddFiles(fileList, parameters, progressMonitor);
}
}
示例7: extractAll
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public void extractAll(final UnzipParameters unzipParameters, final String outPath,
final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
CentralDirectory centralDirectory = zipModel.getCentralDirectory();
if (centralDirectory == null ||
centralDirectory.getFileHeaders() == null) {
throw new ZipException("invalid central directory in zipModel");
}
final ArrayList fileHeaders = centralDirectory.getFileHeaders();
progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_EXTRACT);
progressMonitor.setTotalWork(calculateTotalWork(fileHeaders));
progressMonitor.setState(ProgressMonitor.STATE_BUSY);
if (runInThread) {
Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
public void run() {
try {
initExtractAll(fileHeaders, unzipParameters, progressMonitor, outPath);
progressMonitor.endProgressMonitorSuccess();
} catch (ZipException e) {
}
}
};
thread.start();
} else {
initExtractAll(fileHeaders, unzipParameters, progressMonitor, outPath);
}
}
示例8: initExtractAll
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
private void initExtractAll(ArrayList fileHeaders, UnzipParameters unzipParameters,
ProgressMonitor progressMonitor, String outPath) throws ZipException {
for (int i = 0; i < fileHeaders.size(); i++) {
FileHeader fileHeader = (FileHeader)fileHeaders.get(i);
initExtractFile(fileHeader, outPath, unzipParameters, null, progressMonitor);
if (progressMonitor.isCancelAllTasks()) {
progressMonitor.setResult(ProgressMonitor.RESULT_CANCELLED);
progressMonitor.setState(ProgressMonitor.STATE_READY);
return;
}
}
}
示例9: extractFile
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public void extractFile(final FileHeader fileHeader, final String outPath,
final UnzipParameters unzipParameters, final String newFileName,
final ProgressMonitor progressMonitor, boolean runInThread) throws ZipException {
if (fileHeader == null) {
throw new ZipException("fileHeader is null");
}
progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_EXTRACT);
progressMonitor.setTotalWork(fileHeader.getCompressedSize());
progressMonitor.setState(ProgressMonitor.STATE_BUSY);
progressMonitor.setPercentDone(0);
progressMonitor.setFileName(fileHeader.getFileName());
if (runInThread) {
Thread thread = new Thread(InternalZipConstants.THREAD_NAME) {
public void run() {
try {
initExtractFile(fileHeader, outPath, unzipParameters, newFileName, progressMonitor);
progressMonitor.endProgressMonitorSuccess();
} catch (ZipException e) {
}
}
};
thread.start();
} else {
initExtractFile(fileHeader, outPath, unzipParameters, newFileName, progressMonitor);
progressMonitor.endProgressMonitorSuccess();
}
}
示例10: initProgressMonitorForRemoveOp
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public void initProgressMonitorForRemoveOp(ZipModel zipModel,
FileHeader fileHeader, ProgressMonitor progressMonitor) throws ZipException {
if (zipModel == null || fileHeader == null || progressMonitor == null) {
throw new ZipException("one of the input parameters is null, cannot calculate total work");
}
progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_REMOVE);
progressMonitor.setFileName(fileHeader.getFileName());
progressMonitor.setTotalWork(calculateTotalWorkForRemoveOp(zipModel, fileHeader));
progressMonitor.setState(ProgressMonitor.STATE_BUSY);
}
示例11: initProgressMonitorForMergeOp
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
public void initProgressMonitorForMergeOp(ZipModel zipModel, ProgressMonitor progressMonitor) throws ZipException {
if (zipModel == null) {
throw new ZipException("zip model is null, cannot calculate total work for merge op");
}
progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_MERGE);
progressMonitor.setFileName(zipModel.getZipFile());
progressMonitor.setTotalWork(calculateTotalWorkForMergeOp(zipModel));
progressMonitor.setState(ProgressMonitor.STATE_BUSY);
}
示例12: ZipFile
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Creates a new Zip File Object with the input file.
* If the zip file does not exist, it is not created at this point.
* @param zipFile
* @throws ZipException
*/
public ZipFile(File zipFile) throws ZipException {
if (zipFile == null) {
throw new ZipException("Input zip file parameter is not null",
ZipExceptionConstants.inputZipParamIsNull);
}
this.file = zipFile.getPath();
this.mode = InternalZipConstants.MODE_UNZIP;
this.progressMonitor = new ProgressMonitor();
this.runInThread = false;
}
示例13: addFiles
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Adds the list of input files to the zip file. If zip file does not exist, then
* this method creates a new zip file. Parameters such as compression type, etc
* can be set in the input parameters.
* @param sourceFileList
* @param parameters
* @throws ZipException
*/
public void addFiles(ArrayList sourceFileList, ZipParameters parameters) throws ZipException {
checkZipModel();
if (this.zipModel == null) {
throw new ZipException("internal error: zip model is null");
}
if (sourceFileList == null) {
throw new ZipException("input file ArrayList is null, cannot add files");
}
if (!Zip4jUtil.checkArrayListTypes(sourceFileList, InternalZipConstants.LIST_TYPE_FILE)) {
throw new ZipException("One or more elements in the input ArrayList is not of type File");
}
if (parameters == null) {
throw new ZipException("input parameters are null, cannot add files to zip");
}
if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}
if (Zip4jUtil.checkFileExists(file)) {
if (zipModel.isSplitArchive()) {
throw new ZipException("Zip file already exists. Zip file format does not allow updating split/spanned files");
}
}
ZipEngine zipEngine = new ZipEngine(zipModel);
zipEngine.addFiles(sourceFileList, parameters, progressMonitor, runInThread);
}
示例14: extractAll
import net.lingala.zip4j.progress.ProgressMonitor; //导入依赖的package包/类
/**
* Extracts all the files in the given zip file to the input destination path.
* If zip file does not exist or destination path is invalid then an
* exception is thrown.
* @param destPath
* @param unzipParameters
* @throws ZipException
*/
public void extractAll(String destPath,
UnzipParameters unzipParameters) throws ZipException {
if (!Zip4jUtil.isStringNotNullAndNotEmpty(destPath)) {
throw new ZipException("output path is null or invalid");
}
if (!Zip4jUtil.checkOutputFolder(destPath)) {
throw new ZipException("invalid output path");
}
if (zipModel == null) {
readZipInfo();
}
// Throw an exception if zipModel is still null
if (zipModel == null) {
throw new ZipException("Internal error occurred when extracting zip file");
}
if (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
throw new ZipException("invalid operation - Zip4j is in busy state");
}
Unzip unzip = new Unzip(zipModel);
unzip.extractAll(unzipParameters, destPath, progressMonitor, runInThread);
}