gistfile1.txt package cn.huawei.com.CompressedSeacher.impl.zip;import java.io.IOException;import java.util.Collections;import java.util.Enumeration;import java.util.HashMap;import java.util.Map;import org.apache.tools.zip.ZipEntry;import or
package cn.huawei.com.CompressedSeacher.impl.zip; import java.io.IOException; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import org.apache.tools.zip.ZipEntry; import org.apache.tools.zip.ZipFile; import cn.huawei.com.CompressedSeacher.inter.ISeacher; import cn.huawei.com.CompressedSeacher.util.SeachUtil; import cn.huawei.com.CompressedSeacher.util.logger.GUIPrintstream; import cn.huawei.com.CompressedSeacher.util.logger.LoggerUtil; import cn.huawei.com.CompressedSeacher.view.StartUp; /** * ** * * @author l00358914 */ public class ZipSeacherImpl implements ISeacher { private static ZipSeacherImpl instance = new ZipSeacherImpl(); /** * @param args */ public static void main(String[] args) { } private ZipSeacherImpl() { } public static ZipSeacherImpl getInstance() { return instance; } @Override public Mapseach(String path, String conditions) { if (path == null || path.trim().length() <= 0) { return null; } return paserZipFile(path, conditions); } private Map paserZipFile(String path, String conditions) { if (path == null || path.trim().length() <= 0) { return Collections.EMPTY_MAP; } Map result = new HashMap (); try { ZipFile zip = new ZipFile(path, "UTF-8");// 这里设置支持中文 Enumeration entries = zip.getEntries(); ZipEntry en; String[] cons = conditions.split(","); while (entries.hasMoreElements()) { en = entries.nextElement(); if (cons.length > 0) {// 判断搜索关键字 if (SeachUtil.isOkToAdd(en.getName(), cons)) { result.put(en.getName(), path); } } } } catch (IOException e) { StartUp.logger = LoggerUtil.getLogger(GUIPrintstream.class); StartUp.logger.error("Failed to open this zip file !", e); LoggerUtil.appLog(); return Collections.EMPTY_MAP; } return result; } }