Java Code Examples for net.lingala.zip4j.model.ZipParameters#setSourceExternalStream()

The following examples show how to use net.lingala.zip4j.model.ZipParameters#setSourceExternalStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipUtil.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addEntry(File zip, String entry, InputStream content) {
	try {
		// read war.zip and write to
		ZipFile zipFile = new ZipFile(zip);
		ZipParameters parameters = new ZipParameters();
		parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
		// this would be the name of the file for this entry in the zip file
		parameters.setFileNameInZip(entry);

		// we set this flag to true. If this flag is true, Zip4j identifies
		// that
		// the data will not be from a file but directly from a stream
		parameters.setSourceExternalStream(true);

		// Creates a new entry in the zip file and adds the content to the
		// zip
		// file
		zipFile.addStream(content, parameters);
	} catch (Exception e) {
		logError(e.getMessage());
	}
}
 
Example 2
Source File: BackupAppsTasker.java    From KAM with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected ProgressModel doInBackground(Void... params) {
    List<AppsModel> appsModelList;
    if (appsModels == null) {
        appsModelList = new AppListCreator(context).getAppList();
    } else {
        appsModelList = appsModels;
    }
    if (appsModelList == null) {
        return onError("Apps Are Empty, Please select ones");
    }
    ProgressModel progressModel = new ProgressModel();
    progressModel.setMax(appsModelList.size());
    publishProgress(progressModel);
    try {
        FileUtil fileUtil = new FileUtil();
        File zipFileName = new File(fileUtil.getBaseFolderName() + "backup.zip");
        File zipFileData = new File(fileUtil.getBaseFolderName() + "data.zip");
        zipFile = new ZipFile(zipFileName);
        zipData = new ZipFile(zipFileData);
        if (!zipData.isValidZipFile()) {
            if (zipData.getFile() != null && zipData.getFile().exists())
                zipData.getFile().delete();
        }
        if (!zipFile.isValidZipFile()) {
            if (zipFile.getFile() != null && zipFile.getFile().exists())
                zipFile.getFile().delete();
        }
        int count = 0;
        boolean withData = AppHelper.isBackupData(context);
        if (withData) RootManager.getInstance().obtainPermission();
        for (AppsModel model : appsModelList) {
            if (isCancelled()) {
                return onError("cancelled");
            }
            if (model != null) {
                ApplicationInfo packageInfo = context.getPackageManager().getApplicationInfo(model.getPackageName(), 0);
                File file = new File(packageInfo.sourceDir);
                if (file.exists()) {
                    count++;
                    File fileToSave = fileUtil.generateFile(model.getAppName());
                    progressModel = new ProgressModel();
                    progressModel.setProgress(count);
                    progressModel.setFileName(fileToSave.getName());
                    publishProgress(progressModel);
                    ZipParameters parameters = new ZipParameters();
                    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
                    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
                    parameters.setSourceExternalStream(true);
                    parameters.setFileNameInZip(fileToSave.getName().replaceAll(" ", ""));
                    zipFile.addFile(file, parameters);
                    progressModel = new ProgressModel();
                    progressModel.setProgress(count);
                    progressModel.setFileName(fileToSave.getName());
                    publishProgress(progressModel);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return onError(e.getMessage());
    }

    return null;
}