Android Zip File Create generateKMZ(String inputFileName, String outputFileName)

Here you can find the source of generateKMZ(String inputFileName, String outputFileName)

Description

generates a kmz zip file

License

Open Source License

Parameter

Parameter Description
inputFileName a parameter
outputFileName a parameter

Declaration

public static void generateKMZ(String inputFileName,
        String outputFileName) 

Method Source Code

//package com.java2s;
/*//  w  w  w.  j av a 2  s.  c o m
 *  Copyright (C) 2010-2012 Stichting Akvo (Akvo Foundation)
 *
 *  This file is part of Akvo FLOW.
 *
 *  Akvo FLOW is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo FLOW is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included below for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    private static final int BUFFER = 2048;

    /**
     * generates a kmz zip file
     * 
     * @param inputFileName
     * @param outputFileName
     * @deprecated
     */
    public static void generateKMZ(String inputFileName,
            String outputFileName) {
        try {
            BufferedInputStream origin = null;
            FileOutputStream dest = new FileOutputStream("outputFileName");
            ZipOutputStream out = new ZipOutputStream(
                    new BufferedOutputStream(dest));
            // out.setMethod(ZipOutputStream.DEFLATED);
            byte data[] = new byte[BUFFER];
            // get a list of files from current directory
            File f = new File(inputFileName);
            // String files[] = f.list();

            // for (int i = 0; i < files.length; i++) {
            System.out.println("Adding: " + f.getName());
            FileInputStream fi = new FileInputStream(f);
            origin = new BufferedInputStream(fi, BUFFER);
            ZipEntry entry = new ZipEntry(f.getName());
            out.putNextEntry(entry);
            int count;
            while ((count = origin.read(data, 0, BUFFER)) != -1) {
                out.write(data, 0, count);
            }
            origin.close();
            // }
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. zipFiles(String compressName, File[] files)
  2. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  3. zipFiles(Collection resFileList, File zipFile)
  4. zipFiles(Collection resFileList, File zipFile, String comment)