List of usage examples for java.util.zip ZipFile close
public void close() throws IOException
From source file:com.yunrang.hadoop.app.utils.CustomizedUtil.java
/** * Add entries to <code>packagedClasses</code> corresponding to class files * contained in <code>jar</code>. * //from w w w .j a v a 2s. com * @param jar * The jar who's content to list. * @param packagedClasses * map[class -> jar] */ public static void updateMap(String jar, Map<String, String> packagedClasses) throws IOException { if (null == jar || jar.isEmpty()) { return; } ZipFile zip = null; try { zip = new ZipFile(jar); for (Enumeration<? extends ZipEntry> iter = zip.entries(); iter.hasMoreElements();) { ZipEntry entry = iter.nextElement(); if (entry.getName().endsWith("class")) { packagedClasses.put(entry.getName(), jar); } } } finally { if (null != zip) zip.close(); } }
From source file:org.envirocar.app.util.Util.java
/** * method to get the current version// w w w .j a v a 2 s .c om * */ public static String getVersionString(Context ctx) { StringBuilder out = new StringBuilder("Version "); try { out.append(getVersionStringShort(ctx)); out.append(" ("); out.append(ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0).versionCode); out.append("), "); } catch (NameNotFoundException e) { logger.warn(e.getMessage(), e); } try { ApplicationInfo ai = ctx.getPackageManager().getApplicationInfo(ctx.getPackageName(), 0); ZipFile zf = new ZipFile(ai.sourceDir); ZipEntry ze = zf.getEntry("classes.dex"); long time = ze.getTime(); out.append(SimpleDateFormat.getInstance().format(new java.util.Date(time))); zf.close(); } catch (Exception e) { logger.warn(e.getMessage(), e); } return out.toString(); }
From source file:org.opf_labs.fmts.corpora.govdocs.GovDocs.java
private static final FolderDetails getZipFolderDetails(final File zipFolder) throws ZipException, IOException { ZipFile zipFile = new ZipFile(zipFolder); Enumeration<? extends ZipEntry> entries = zipFile.entries(); ZipEntry entry = null;// w w w . j av a2 s .c o m int count = 0; long size = 0L; final Set<String> exts = new HashSet<String>(); while (entries.hasMoreElements()) { entry = entries.nextElement(); if (!entry.isDirectory()) { count++; size += entry.getSize(); exts.add(FilenameUtils.getExtension(entry.getName())); } } zipFile.close(); FolderDetails dets = new FolderDetails(count, size, exts); return dets; }
From source file:Main.java
/** * Get channel from META-INF directory.//w ww . j a v a 2 s .co m * * @return the channel name if success,otherwise return "none" */ public static String getChannel(Context context) { ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; String ret = ""; ZipFile zipfile = null; try { zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith("META-INF/channel")) { ret = entryName; break; } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } String[] split = ret.split("_"); if (split != null && split.length >= 2) { return ret.substring(split[0].length() + 1); } else { return "none"; } }
From source file:ClassFinder.java
private static void findClassesInOnePath(String strPath, Set<String> listClasses) throws IOException { File file = new File(strPath); if (file.isDirectory()) { findClassesInPathsDir(strPath, file, listClasses); } else if (file.exists()) { ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { String strEntry = entries.nextElement().toString(); if (strEntry.endsWith(DOT_CLASS)) { listClasses.add(fixClassName(strEntry)); }// w w w . ja v a2 s. c o m } zipFile.close(); } }
From source file:Main.java
private static String getChannelFromApk(Context context, String channelKey) { ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; String key = "META-INF/" + channelKey; String ret = ""; ZipFile zipfile = null; try {//from w w w .j a v a 2 s . c om zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) { ret = entryName; break; } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } String[] split = ret.split("_"); String channel = ""; if (split != null && split.length >= 2) { channel = ret.substring(split[0].length() + 1); } return channel; }
From source file:org.elasticwarehouse.core.ResourceTools.java
private static Collection<String> getResourcesFromJarFile(final File file, final Pattern pattern) { final ArrayList<String> retval = new ArrayList<String>(); ZipFile zf; try {//from w w w . j a va 2 s. c o m zf = new ZipFile(file); } catch (final ZipException e) { throw new Error(e); } catch (final IOException e) { throw new Error(e); } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { final ZipEntry ze = (ZipEntry) e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { retval.add(fileName); } } try { zf.close(); } catch (final IOException e1) { throw new Error(e1); } return retval; }
From source file:Main.java
public static String getChannel(Context context) { ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; ZipFile zipfile = null; String ret = null;// ww w .j a v a 2s . co m try { zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(FOLDER_NAME) && entryName.contains(CHANNEL_SCHEME)) { ret = entryName; break; } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } try { if (ret != null) { String[] split = ret.split(CHANNEL_SCHEME_SPIT); if (split.length >= 2) { return ret.substring(split[0].length() + 1); } } } catch (Exception e) { } return null; }
From source file:ClassFinder.java
private static void findClassesInPathsDir(String strPathElement, File dir, Set<String> listClasses) throws IOException { String[] list = dir.list();//from www.ja v a 2 s.c o m for (int i = 0; i < list.length; i++) { File file = new File(dir, list[i]); if (file.isDirectory()) { // Recursive call findClassesInPathsDir(strPathElement, file, listClasses); } else if (list[i].endsWith(DOT_CLASS) && file.exists() && (file.length() != 0)) { final String path = file.getPath(); listClasses.add(path.substring(strPathElement.length() + 1, path.lastIndexOf(".")) // $NON-NLS-1$ .replace(File.separator.charAt(0), '.')); // $NON-NLS-1$ } else if (list[i].endsWith(DOT_JAR) && file.exists() && (file.length() != 0)) { ZipFile zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { String strEntry = entries.nextElement().toString(); if (strEntry.endsWith(DOT_CLASS)) { listClasses.add(fixClassName(strEntry)); } } zipFile.close(); } } }
From source file:com.openkm.util.DocumentUtils.java
/** * Text spell checker/*from w w w. j av a 2s . c o m*/ */ public static String spellChecker(String text) throws IOException { log.debug("spellChecker({})", text); StringBuilder sb = new StringBuilder(); if (Config.SYSTEM_OPENOFFICE_DICTIONARY.equals("")) { log.warn("OpenOffice dictionary not configured"); sb.append(text); } else { log.info("Using OpenOffice dictionary: {}", Config.SYSTEM_OPENOFFICE_DICTIONARY); ZipFile zf = new ZipFile(Config.SYSTEM_OPENOFFICE_DICTIONARY); OpenOfficeSpellDictionary oosd = new OpenOfficeSpellDictionary(zf); SpellChecker sc = new SpellChecker(oosd); sc.setCaseSensitive(false); StringTokenizer st = new StringTokenizer(text); while (st.hasMoreTokens()) { String w = st.nextToken(); List<String> s = sc.getDictionary().getSuggestions(w); if (s.isEmpty()) { sb.append(w).append(" "); } else { sb.append(s.get(0)).append(" "); } } zf.close(); } log.debug("spellChecker: {}", sb.toString()); return sb.toString(); }