/**
* Copyright (C) 2012-2013 eBusiness Information (www.ebusinessinformation.fr)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.athomas.androidkickstartr.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class Zipper {
public static void zip(File srcFolder, File zipFile) throws IOException {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile));
addDir(srcFolder, out);
out.close();
}
private static void addDir(File dirObj, ZipOutputStream out) throws IOException {
File[] files = dirObj.listFiles();
byte[] tmpBuf = new byte[1024];
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.isDirectory()) {
addDir(file, out);
continue;
}
FileInputStream in = new FileInputStream(file.getPath());
String zipPath = file.getPath();
zipPath = zipPath.replace("generated/", "");
out.putNextEntry(new ZipEntry(zipPath));
int len;
while ((len = in.read(tmpBuf)) > 0) {
out.write(tmpBuf, 0, len);
}
out.closeEntry();
in.close();
}
}
}