package org.onetwo.plugins.email;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import org.apache.tools.zip.ZipEntry;
import org.apache.tools.zip.ZipOutputStream;
import org.onetwo.common.exception.BaseException;
import org.onetwo.common.log.MyLoggerFactory;
import org.onetwo.common.utils.Assert;
import org.onetwo.common.utils.FileUtils;
import org.slf4j.Logger;

public class ZipUtils {
	private static final Logger logger = MyLoggerFactory.getLogger(ZipUtils.class);

	public static File zipfile(String targetZipFilePath, File file){
		return zipfile(targetZipFilePath, file, file.isFile());
	}
	
	public static File zipfile(String targetZipFilePath, File file, boolean isfile){
		if(isfile){
			return zipfiles(targetZipFilePath, file);
		}else{
			List<File> files = FileUtils.listFile(file);
			return zipfiles(targetZipFilePath, files.toArray(new File[0]));
		}
	}

	public static File zipfile(File file, String encoding){
		String targetZipFilePath = FileUtils.getNewFilenameBy(file, ".zip");
		return zipfile(targetZipFilePath, file);
	}

	public static File zipfiles(String targetZipFilePath, File...files){
		return zipfiles(targetZipFilePath, FileUtils.UTF8, files);
	}
	public static File zipfiles(String targetZipFilePath, String encoding, File...files){
		Assert.notEmpty(files);
		File zipfile = new File(targetZipFilePath);
		FileUtils.makeDirs(zipfile, true);
		ZipOutputStream zipout = null;
		try {
			zipout = new ZipOutputStream(new FileOutputStream(zipfile));
			zipout.setEncoding(encoding);
			for(File f : files){
				String entryName = f.getName();
				ZipEntry zipentry = new ZipEntry(entryName);
				logger.info("put entry: " + entryName);
				zipout.putNextEntry(zipentry);
				FileUtils.copyFileToOutputStream(zipout, f);
			}
			zipout.finish();
		} catch (Exception e) {
			throw new BaseException("zip file error: " + e.getMessage(), e);
		} finally{
			FileUtils.close(zipout);
		}
		return zipfile;
	}
	
	private ZipUtils() {
	}

}

@@ -252,55 +252,8 @@
 n;%0D%0A
-import org.onetwo.common.log.MyLoggerFactory;%0D%0A
 impo
@@ -334,34 +334,8 @@
 ls;%0D
-%0Aimport org.slf4j.Logger;%0D
 %0A%0D%0Ap
@@ -358,16 +358,18 @@
 tils %7B%0D%0A
+//
 %09private
@@ -1626,24 +1626,26 @@
 ntryName);%0D%0A
+//
 %09%09%09%09logger.i

fix ziputils, remove logger