Browse Source

增加StringUtils

sunyj 8 years ago
parent
commit
9d92389bb0

+ 1 - 1
src/main/java/com/uas/report/aop/AxisServiceLogAspect.java

@@ -11,7 +11,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Component;
 
-import com.alibaba.druid.util.StringUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * 利用AOP处理Axis Service日志

+ 1 - 1
src/main/java/com/uas/report/aop/WebLogAspect.java

@@ -13,8 +13,8 @@ import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.stereotype.Component;
 
-import com.alibaba.druid.util.StringUtils;
 import com.uas.report.util.IpHelper;
+import com.uas.report.util.StringUtils;
 
 /**
  * 利用AOP处理Web请求日志

+ 2 - 3
src/main/java/com/uas/report/axis/BasicResourceHandler.java

@@ -9,12 +9,11 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
-
 import com.uas.report.SpecialProperties;
+import com.uas.report.util.CollectionUtils;
 import com.uas.report.util.ContextUtils;
 import com.uas.report.util.FileUtils;
+import com.uas.report.util.StringUtils;
 
 public class BasicResourceHandler implements ResourceHandler {
 

+ 1 - 1
src/main/java/com/uas/report/axis/ResourceDescriptor.java

@@ -6,7 +6,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 
-import org.springframework.util.StringUtils;
+import com.uas.report.util.StringUtils;
 
 public class ResourceDescriptor {
 

+ 1 - 1
src/main/java/com/uas/report/controller/FileController.java

@@ -8,7 +8,6 @@ import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.ResponseBody;
@@ -16,6 +15,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import com.uas.report.service.FileService;
 import com.uas.report.util.ArrayUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * 文件操作请求

+ 1 - 1
src/main/java/com/uas/report/controller/PrintController.java

@@ -16,7 +16,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.ResponseBody;
 
@@ -27,6 +26,7 @@ import com.uas.report.util.ArrayUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * 报表打印

+ 1 - 1
src/main/java/com/uas/report/core/advice/ExceptionHandlerAdvice.java

@@ -13,12 +13,12 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.ui.ModelMap;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.ControllerAdvice;
 import org.springframework.web.bind.annotation.ExceptionHandler;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.report.core.exception.ReportException;
+import com.uas.report.util.StringUtils;
 
 /**
  * <p>

+ 21 - 6
src/main/java/com/uas/report/crystal2jasper/CrystalToJasper.java

@@ -12,9 +12,9 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.util.Set;
 
 import javax.xml.transform.TransformerException;
 
@@ -28,14 +28,14 @@ import org.dom4j.io.SAXReader;
 import org.dom4j.io.XMLWriter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
 import com.uas.report.core.exception.ReportException;
 import com.uas.report.crystal2jasper.Join.JoinType;
 import com.uas.report.crystal2jasper.Link.LinkType;
 import com.uas.report.crystal2jasper.Sort.SortType;
+import com.uas.report.util.CollectionUtils;
 import com.uas.report.util.FileUtils;
+import com.uas.report.util.StringUtils;
 import com.uas.report.util.ZipUtils;
 
 public class CrystalToJasper {
@@ -43,12 +43,27 @@ public class CrystalToJasper {
 	private static Logger logger = LoggerFactory.getLogger(CrystalToJasper.class);
 
 	public static void main(String[] args) throws IOException, DocumentException, TransformerException {
-		File rptZipFile = new File("C:/Users/sunyj-pc/Desktop/crystal-clear/formatted");
-		File outDir = new File("C:/Users/sunyj-pc/Desktop/crystal-clear/formatted/out");
+		File rptZipFile = new File("C:/Users/sunyj-pc/Desktop/temp/crystal-clear/formatted");
+		File outDir = new File("C:/Users/sunyj-pc/Desktop/temp/crystal-clear/formatted/out");
 		File styleFile = new File("src/main/resources/crystal2jasper.xsl");
+		boolean remainHierarchy = false;
+
+		int length = args != null ? args.length : 0;
+		if (length >= 1) {
+			rptZipFile = new File(args[0]);
+		}
+		if (length >= 2) {
+			outDir = new File(args[1]);
+		}
+		if (length >= 3) {
+			styleFile = new File(args[2]);
+		}
+		if (length >= 4) {
+			remainHierarchy = Boolean.parseBoolean(args[3]);
+		}
 
 		CrystalToJasper crystalToJasper = new CrystalToJasper();
-		crystalToJasper.translate(rptZipFile, outDir, false, styleFile);
+		crystalToJasper.translate(rptZipFile, outDir, remainHierarchy, styleFile);
 		logger.info("translation complete!");
 	}
 

+ 1 - 1
src/main/java/com/uas/report/crystal2jasper/Sort.java

@@ -1,6 +1,6 @@
 package com.uas.report.crystal2jasper;
 
-import org.springframework.util.StringUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * @author sunyj

+ 2 - 1
src/main/java/com/uas/report/jasperreports/engine/export/CustomJRXlsExporter.java

@@ -3,7 +3,8 @@ package com.uas.report.jasperreports.engine.export;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.ss.usermodel.IndexedColors;
-import org.springframework.util.StringUtils;
+
+import com.uas.report.util.StringUtils;
 
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRPrintText;

+ 1 - 1
src/main/java/com/uas/report/model/Master.java

@@ -1,6 +1,6 @@
 package com.uas.report.model;
 
-import org.springframework.util.StringUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * 账套

+ 2 - 2
src/main/java/com/uas/report/schedule/service/impl/TaskServiceImpl.java

@@ -13,14 +13,14 @@ import java.util.concurrent.TimeUnit;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
 import com.uas.report.core.exception.ReportException;
 import com.uas.report.schedule.model.TaskInformation;
 import com.uas.report.schedule.model.TaskLog;
 import com.uas.report.schedule.service.Executable;
 import com.uas.report.schedule.service.TaskService;
+import com.uas.report.util.CollectionUtils;
+import com.uas.report.util.StringUtils;
 
 /**
  * 管理定时任务

+ 19 - 18
src/main/java/com/uas/report/service/impl/FileServiceImpl.java

@@ -27,7 +27,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import com.alibaba.druid.util.StringUtils;
 import com.alibaba.fastjson.JSONObject;
 import com.lowagie.text.Document;
 import com.lowagie.text.DocumentException;
@@ -43,6 +42,7 @@ import com.uas.report.util.ArrayUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
+import com.uas.report.util.StringUtils;
 import com.uas.report.util.ZipUtils;
 
 @Service
@@ -227,12 +227,12 @@ public class FileServiceImpl implements FileService {
 		if (!specialProperties.hasStandardJrxmls()) {
 			throw new ReportException("没有" + userName + "标准模板!");
 		}
-		byte[] data = ZipUtils.zipFolder(getMasterPath(specialProperties.getStandardMaster()) + "/" + userName,
-				FileServiceImpl.fileFilter);
-		if (ArrayUtils.isEmpty(data)) {
-			throw new ReportException("压缩失败");
+		try {
+			return ZipUtils.zipFolder(getMasterPath(specialProperties.getStandardMaster()) + "/" + userName,
+					FileServiceImpl.fileFilter);
+		} catch (Throwable e) {
+			throw new ReportException("压缩失败").setDetailedMessage(e);
 		}
-		return data;
 	}
 
 	@Override
@@ -252,11 +252,12 @@ public class FileServiceImpl implements FileService {
 			throw new ReportException("未传入当前账套名称!");
 		}
 		String masterPath = getMasterPath(userName);
-		byte[] data = ZipUtils.zipFolder(masterPath, FileServiceImpl.fileFilter);
-		if (ArrayUtils.isEmpty(data)) {
-			throw new ReportException("压缩失败");
+		try {
+			byte[] data = ZipUtils.zipFolder(masterPath, FileServiceImpl.fileFilter);
+			download(data, new File(masterPath).getName() + ".zip", response);
+		} catch (Throwable e) {
+			throw new ReportException("压缩失败").setDetailedMessage(e);
 		}
-		download(data, new File(masterPath).getName() + ".zip", response);
 	}
 
 	@Override
@@ -273,19 +274,19 @@ public class FileServiceImpl implements FileService {
 		byte[] data = null;
 		String fileName = "";
 		// 下载文件夹之前,需进行压缩
-		if (file.isDirectory()) {
-			fileName = file.getName() + ".zip";
-			data = ZipUtils.zipFolder(filePath, fileFilter);
-		} else {
-			fileName = file.getName();
-			try {
+		try {
+			if (file.isDirectory()) {
+				fileName = file.getName() + ".zip";
+				data = ZipUtils.zipFolder(filePath, fileFilter);
+			} else {
+				fileName = file.getName();
 				InputStream inputStream = new FileInputStream(file);
 				data = new byte[inputStream.available()];
 				inputStream.read(data);
 				inputStream.close();
-			} catch (IOException e) {
-				logger.error("", e);
 			}
+		} catch (IOException e) {
+			throw new ReportException(e.getMessage()).setDetailedMessage(e);
 		}
 		if (ArrayUtils.isEmpty(data)) {
 			throw new ReportException("下载失败:" + filePath);

+ 2 - 2
src/main/java/com/uas/report/service/impl/PrintServiceImpl.java

@@ -39,8 +39,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
 
 import com.alibaba.fastjson.JSONObject;
 import com.uas.report.SpecialProperties;
@@ -50,10 +48,12 @@ import com.uas.report.model.Master;
 import com.uas.report.service.FileService;
 import com.uas.report.service.PrintService;
 import com.uas.report.util.ArrayUtils;
+import com.uas.report.util.CollectionUtils;
 import com.uas.report.util.FileUtils;
 import com.uas.report.util.MasterManager;
 import com.uas.report.util.ReportConstants;
 import com.uas.report.util.ReportUtils;
+import com.uas.report.util.StringUtils;
 
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JasperCompileManager;

+ 5 - 0
src/main/java/com/uas/report/util/CollectionUtils.java

@@ -1,6 +1,7 @@
 package com.uas.report.util;
 
 import java.util.Collection;
+import java.util.Map;
 
 /**
  * @author sunyj
@@ -11,4 +12,8 @@ public class CollectionUtils {
 	public static boolean isEmpty(Collection<?> coll) {
 		return (coll == null || coll.isEmpty());
 	}
+
+	public static boolean isEmpty(Map<?, ?> map) {
+		return (map == null || map.isEmpty());
+	}
 }

+ 164 - 3
src/main/java/com/uas/report/util/FileUtils.java

@@ -2,13 +2,19 @@ package com.uas.report.util;
 
 import java.io.File;
 import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.alibaba.druid.util.StringUtils;
 import com.uas.report.core.exception.ReportException;
 
 /**
@@ -66,6 +72,27 @@ public class FileUtils {
 		}
 	}
 
+	/**
+	 * 向文件写入内容
+	 * 
+	 * @param file
+	 *            文件
+	 * @param content
+	 *            写入的内容
+	 * @return 写入的文件
+	 */
+	public static File write(File file, String content) throws IOException {
+		if (!file.getParentFile().exists()) {
+			file.getParentFile().mkdirs();
+		}
+		file.createNewFile();
+		// 以UTF-8编码方式写入文件
+		OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
+		writer.write(content);
+		writer.close();
+		return file;
+	}
+
 	/**
 	 * 递归删除文件(夹)
 	 * 
@@ -76,6 +103,18 @@ public class FileUtils {
 		deleteDir(file, null);
 	}
 
+	/**
+	 * 递归删除文件(夹)
+	 * 
+	 * @param file
+	 *            文件(夹)
+	 * @param printLogger
+	 *            是否输出logger信息
+	 */
+	public static void deleteDir(File file, boolean printLogger) {
+		deleteDir(file, null, printLogger);
+	}
+
 	/**
 	 * 递归删除文件(夹)
 	 * 
@@ -85,13 +124,27 @@ public class FileUtils {
 	 *            文件过滤
 	 */
 	public static void deleteDir(File file, FileFilter filter) {
+		deleteDir(file, filter, true);
+	}
+
+	/**
+	 * 递归删除文件(夹)
+	 * 
+	 * @param file
+	 *            文件(夹)
+	 * @param filter
+	 *            文件过滤
+	 * @param printLogger
+	 *            是否输出logger信息
+	 */
+	public static void deleteDir(File file, FileFilter filter, boolean printLogger) {
 		if (file == null) {
 			return;
 		}
 		if (file.isDirectory()) {
 			File[] files = file.listFiles();
 			for (File f : files) {
-				deleteDir(f, filter);
+				deleteDir(f, filter, printLogger);
 			}
 		}
 		// 如果文件不符合条件,则不删除
@@ -99,6 +152,114 @@ public class FileUtils {
 			return;
 		}
 		file.delete();
-		logger.info("Deleted... " + file.getPath());
+		if (printLogger) {
+			logger.info("Deleted... " + file.getPath());
+		}
+	}
+
+	public static void move(File src, File dest) throws IOException {
+		copy(src, dest);
+		delete(src);
+	}
+
+	public static void copy(File src, File dest) throws IOException {
+		logger.trace("copy() - source file: {}, exists: {}", src.getAbsolutePath(), Boolean.valueOf(src.exists()));
+		ReadableByteChannel in = Channels.newChannel(new FileInputStream(src));
+
+		logger.trace("copy() - dest file: {}, exists: {}", dest.getAbsolutePath(), Boolean.valueOf(dest.exists()));
+		WritableByteChannel out = Channels.newChannel(new FileOutputStream(dest));
+
+		logger.trace("copy() Copying...");
+		copyChannel(in, out);
+
+		logger.trace("copy() Closing files...");
+		in.close();
+		out.close();
+	}
+
+	public static boolean delete(File f) {
+		boolean deleted = true;
+		if ((f != null) && (f.exists())) {
+			logger.trace("delete() Deleting file: {}", f);
+			System.gc();
+			System.runFinalization();
+			deleted = f.delete();
+		} else {
+			logger.trace("delete() File doesn't exist: {}", f);
+		}
+		return deleted;
+	}
+
+	private static void copyChannel(ReadableByteChannel source, WritableByteChannel dest) throws IOException {
+		ByteBuffer buffer = ByteBuffer.allocateDirect(32768);
+
+		while (source.read(buffer) != -1) {
+			buffer.flip();
+
+			dest.write(buffer);
+
+			buffer.compact();
+		}
+
+		buffer.flip();
+
+		while (buffer.hasRemaining())
+			dest.write(buffer);
+	}
+
+	/**
+	 * 检查文件
+	 * 
+	 * @param file
+	 * @throws FileNotFoundException
+	 *             文件不存在
+	 */
+	public static void checkFile(File file) throws FileNotFoundException {
+		if (!file.exists()) {
+			throw new FileNotFoundException(file.getAbsolutePath());
+		}
+	}
+
+	/**
+	 * 检查文件夹
+	 * 
+	 * @param dir
+	 * @throws FileNotFoundException
+	 *             文件夹不存在
+	 */
+	public static void checkDir(File dir) throws FileNotFoundException {
+		checkFile(dir);
+		if (dir.isFile()) {
+			throw new ReportException("路径并非文件夹:" + dir.getAbsolutePath());
+		}
+	}
+
+	/**
+	 * 初始化文件夹,不存在则创建
+	 * 
+	 * @param dir
+	 * @return
+	 * @throws FileNotFoundException
+	 */
+	public static File initDir(File dir) throws FileNotFoundException {
+		if (!dir.exists()) {
+			dir.mkdirs();
+		}
+		checkDir(dir);
+		return dir;
+	}
+
+	/**
+	 * 去除文件名称的后缀
+	 * 
+	 * @param fileName
+	 *            文件名称
+	 * @return 去除后缀的文件名称
+	 */
+	public static String removeSuffix(String fileName) {
+		if (!fileName.contains(".")) {
+			return fileName;
+		}
+		return fileName.substring(0, fileName.lastIndexOf("."));
 	}
 }

+ 0 - 1
src/main/java/com/uas/report/util/MasterManager.java

@@ -14,7 +14,6 @@ import javax.sql.DataSource;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.util.StringUtils;
 
 import com.alibaba.druid.pool.DruidDataSource;
 import com.alibaba.fastjson.JSONObject;

+ 0 - 2
src/main/java/com/uas/report/util/ReportUtils.java

@@ -1,7 +1,5 @@
 package com.uas.report.util;
 
-import org.springframework.util.StringUtils;
-
 import com.uas.report.SystemProperties;
 import com.uas.report.core.exception.ReportException;
 import com.uas.report.schedule.service.TaskService;

+ 12 - 0
src/main/java/com/uas/report/util/StringUtils.java

@@ -0,0 +1,12 @@
+package com.uas.report.util;
+
+/**
+ * @author sunyj
+ * @since 2017年5月25日 上午11:09:36
+ */
+public class StringUtils {
+
+	public static boolean isEmpty(Object str) {
+		return (str == null || "".equals(str));
+	}
+}

+ 73 - 89
src/main/java/com/uas/report/util/ZipUtils.java

@@ -18,7 +18,6 @@ import java.util.zip.ZipOutputStream;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.alibaba.druid.util.StringUtils;
 import com.uas.report.core.exception.ReportException;
 
 /**
@@ -39,8 +38,9 @@ public class ZipUtils {
 	 * @param fileFilter
 	 *            文件过滤器,不压缩某些文件
 	 * @return 压缩后的数据
+	 * @throws IOException
 	 */
-	public static byte[] zipFolder(String sourceFolderPath, FileFilter fileFilter) {
+	public static byte[] zipFolder(String sourceFolderPath, FileFilter fileFilter) throws IOException {
 		if (StringUtils.isEmpty(sourceFolderPath)) {
 			return null;
 		}
@@ -55,16 +55,12 @@ public class ZipUtils {
 
 		ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 		byte[] zipData = null;
-		try {
-			ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
-			putNextEntryFromFolder(zipOutputStream, folder, "", fileFilter);
-			zipOutputStream.close();
-			logger.info("Zip done");
-			zipData = outputStream.toByteArray();
-			outputStream.close();
-		} catch (IOException e) {
-			logger.error("", e);
-		}
+		ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream);
+		putNextEntryFromFolder(zipOutputStream, folder, "", fileFilter);
+		zipOutputStream.close();
+		logger.info("Zip done");
+		zipData = outputStream.toByteArray();
+		outputStream.close();
 		return zipData;
 	}
 
@@ -77,8 +73,10 @@ public class ZipUtils {
 	 *            压缩后的压缩包路径
 	 * @param fileFilter
 	 *            文件过滤器,不压缩某些文件
+	 * @throws IOException
 	 */
-	public static void zipFolder(String sourceFolderPath, String zipFilePath, FileFilter fileFilter) {
+	public static void zipFolder(String sourceFolderPath, String zipFilePath, FileFilter fileFilter)
+			throws IOException {
 		if (StringUtils.isEmpty(sourceFolderPath) || StringUtils.isEmpty(zipFilePath)) {
 			return;
 		}
@@ -91,14 +89,10 @@ public class ZipUtils {
 			throw new ReportException("空文件夹:" + sourceFolderPath);
 		}
 
-		try {
-			ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFilePath));
-			putNextEntryFromFolder(zipOutputStream, folder, "", fileFilter);
-			zipOutputStream.close();
-			logger.info("Zip finished to... " + zipFilePath);
-		} catch (IOException e) {
-			logger.error("", e);
-		}
+		ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipFilePath));
+		putNextEntryFromFolder(zipOutputStream, folder, "", fileFilter);
+		zipOutputStream.close();
+		logger.info("Zip finished to... " + zipFilePath);
 	}
 
 	/**
@@ -112,31 +106,28 @@ public class ZipUtils {
 	 *            为保持压缩后的路径层次不变,所记录的当前文件夹的相对层级
 	 * @param fileFilter
 	 *            文件过滤器,不压缩某些文件
+	 * @throws IOException
 	 */
 	private static void putNextEntryFromFolder(ZipOutputStream zipOutputStream, File folder, String prefix,
-			FileFilter fileFilter) {
+			FileFilter fileFilter) throws IOException {
 		File[] files = folder.listFiles();
-		try {
-			for (File file : files) {
-				if (file.isDirectory()) {
-					putNextEntryFromFolder(zipOutputStream, file, prefix + file.getName() + File.separator, fileFilter);
-				} else {
-					// 过滤某些文件
-					if (fileFilter != null && !fileFilter.accept(file)) {
-						continue;
-					}
-					zipOutputStream.putNextEntry(new ZipEntry(prefix + file.getName()));
-					InputStream inputStream = new FileInputStream(file);
-					int b;
-					while ((b = inputStream.read()) != -1) {
-						zipOutputStream.write(b);
-					}
-					inputStream.close();
+		for (File file : files) {
+			if (file.isDirectory()) {
+				putNextEntryFromFolder(zipOutputStream, file, prefix + file.getName() + File.separator, fileFilter);
+			} else {
+				// 过滤某些文件
+				if (fileFilter != null && !fileFilter.accept(file)) {
+					continue;
+				}
+				zipOutputStream.putNextEntry(new ZipEntry(prefix + file.getName()));
+				InputStream inputStream = new FileInputStream(file);
+				int b;
+				while ((b = inputStream.read()) != -1) {
+					zipOutputStream.write(b);
 				}
-				logger.info("Ziped from... " + file.getPath());
+				inputStream.close();
 			}
-		} catch (IOException e) {
-			logger.error("", e);
+			logger.info("Ziped from... " + file.getPath());
 		}
 	}
 
@@ -147,36 +138,33 @@ public class ZipUtils {
 	 *            压缩包数据
 	 * @param folderPath
 	 *            解压缩后的文件路径
+	 * @throws IOException
 	 */
-	public static void unzip(byte[] zipData, String folderPath) {
+	public static void unzip(byte[] zipData, String folderPath) throws IOException {
 		if (StringUtils.isEmpty(folderPath)) {
 			return;
 		}
 
-		try {
-			ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(zipData));
-			ZipEntry zipEntry;
-			while ((zipEntry = zipInputStream.getNextEntry()) != null) {
-				if (zipEntry.isDirectory()) {
-					continue;
-				}
-				File outFile = new File(folderPath + File.separator + zipEntry.getName());
-				if (!outFile.getParentFile().exists()) {
-					outFile.getParentFile().mkdirs();
-				}
+		ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(zipData));
+		ZipEntry zipEntry;
+		while ((zipEntry = zipInputStream.getNextEntry()) != null) {
+			if (zipEntry.isDirectory()) {
+				continue;
+			}
+			File outFile = new File(folderPath + File.separator + zipEntry.getName());
+			if (!outFile.getParentFile().exists()) {
+				outFile.getParentFile().mkdirs();
+			}
 
-				OutputStream outputStream = new FileOutputStream(outFile);
-				int b;
-				while ((b = zipInputStream.read()) != -1) {
-					outputStream.write(b);
-				}
-				outputStream.close();
-				logger.info("Unziped to... " + outFile.getPath());
+			OutputStream outputStream = new FileOutputStream(outFile);
+			int b;
+			while ((b = zipInputStream.read()) != -1) {
+				outputStream.write(b);
 			}
-			zipInputStream.close();
-		} catch (IOException e) {
-			logger.error("", e);
+			outputStream.close();
+			logger.info("Unziped to... " + outFile.getPath());
 		}
+		zipInputStream.close();
 		logger.info("Unzip done");
 	}
 
@@ -187,8 +175,9 @@ public class ZipUtils {
 	 *            将解压缩的压缩包路径
 	 * @param zipFilePath
 	 *            解压缩后的文件路径
+	 * @throws IOException
 	 */
-	public static void unzip(String zipFilePath, String folderPath) {
+	public static void unzip(String zipFilePath, String folderPath) throws IOException {
 		if (StringUtils.isEmpty(zipFilePath) || StringUtils.isEmpty(folderPath)) {
 			return;
 		}
@@ -205,34 +194,29 @@ public class ZipUtils {
 			throw new ReportException("并非文件夹:" + folderPath);
 		}
 
-		try {
-			ZipFile zipFile = new ZipFile(file);
-			Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
-			while (zipEntries.hasMoreElements()) {
-				ZipEntry zipEntry = zipEntries.nextElement();
-				if (zipEntry.isDirectory()) {
-					continue;
-				}
-				InputStream inputStream = zipFile.getInputStream(zipEntry);
-				File outFile = new File(folder.getPath() + File.separator + zipEntry.getName());
-				if (!outFile.getParentFile().exists()) {
-					outFile.getParentFile().mkdirs();
-				}
+		ZipFile zipFile = new ZipFile(file);
+		Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
+		while (zipEntries.hasMoreElements()) {
+			ZipEntry zipEntry = zipEntries.nextElement();
+			if (zipEntry.isDirectory()) {
+				continue;
+			}
+			InputStream inputStream = zipFile.getInputStream(zipEntry);
+			File outFile = new File(folder.getPath() + File.separator + zipEntry.getName());
+			if (!outFile.getParentFile().exists()) {
+				outFile.getParentFile().mkdirs();
+			}
 
-				String fileName = folder.getPath() + File.separator + zipEntry.getName();
-				OutputStream outputStream = new FileOutputStream(fileName);
-				int b;
-				while ((b = inputStream.read()) != -1) {
-					outputStream.write(b);
-				}
-				inputStream.close();
-				outputStream.close();
-				logger.info("Unziped to... " + fileName);
+			String fileName = folder.getPath() + File.separator + zipEntry.getName();
+			OutputStream outputStream = new FileOutputStream(fileName);
+			int b;
+			while ((b = inputStream.read()) != -1) {
+				outputStream.write(b);
 			}
-			zipFile.close();
-		} catch (IOException e) {
-			logger.error("", e);
+			inputStream.close();
+			outputStream.close();
 		}
+		zipFile.close();
 		logger.info("Unzip finished from... " + zipFilePath);
 	}
 }