List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:com.baomidou.framework.common.JarHelper.java
public static List<String> listFiles(JarFile jarFile, String endsWith) { if (jarFile == null || StringUtils.isEmpty(endsWith)) { return null; }/* ww w. j av a2 s .c om*/ List<String> files = new ArrayList<String>(); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String name = entry.getName(); if (name.endsWith(endsWith)) { files.add(name); } } return files; }
From source file:Main.java
public static <T> Iterable<T> iterate(Enumeration<T> enumeration) { List<T> list = new ArrayList<T>(); while (enumeration.hasMoreElements()) { list.add(enumeration.nextElement()); }// w w w . ja va 2 s . c om return list; }
From source file:Main.java
/** * To check if the apk file is available to install. * //from w w w . j a v a 2 s .c o m * @param apkFilePath the apk file path * @return true if available, otherwise return false */ public static boolean isApkAvailable(String apkFilePath) { File apkFile = new File(apkFilePath); if (!apkFile.exists()) { return false; } try { ZipFile zipFile = new ZipFile(apkFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); if (APK_MANIFEST.equals(zipEntry.getName())) { zipFile.close(); return true; } } zipFile.close(); } catch (Exception e) { return false; } return false; }
From source file:irille.pub.verify.RandomImageServlet.java
public static String getHeader(HttpServletRequest req, String name) { String value = req.getHeader(name); if (value != null) return value; Enumeration names = req.getHeaderNames(); while (names.hasMoreElements()) { String n = (String) names.nextElement(); if (n.equalsIgnoreCase(name)) { return req.getHeader(n); }/*from w w w. jav a 2 s .co m*/ } return null; }
From source file:Main.java
/** * Sets all used fonts for displaying to the specified font df * <br>Use with care! // w w w . j a va 2 s . c o m */ public static void setUIFont(final Font df) { setUIFontSize(df.getSize()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; final Font ofont = new FontUIResource(df.getName(), ifont.getStyle(), df.getSize()); UIManager.put(key, ofont); } } }
From source file:Main.java
/** * Uncompresses zipped files/*from w w w .j av a 2 s . c o m*/ * @param zippedFile The file to uncompress * @param destinationDir Where to put the files * @return list of unzipped files * @throws java.io.IOException thrown if there is a problem finding or writing the files */ public static List<File> unzip(File zippedFile, File destinationDir) throws IOException { int buffer = 2048; List<File> unzippedFiles = new ArrayList<File>(); BufferedOutputStream dest; BufferedInputStream is; ZipEntry entry; ZipFile zipfile = new ZipFile(zippedFile); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[buffer]; File destFile; if (destinationDir != null) { destFile = new File(destinationDir, entry.getName()); } else { destFile = new File(entry.getName()); } FileOutputStream fos = new FileOutputStream(destFile); dest = new BufferedOutputStream(fos, buffer); try { while ((count = is.read(data, 0, buffer)) != -1) { dest.write(data, 0, count); } unzippedFiles.add(destFile); } finally { dest.flush(); dest.close(); is.close(); } } return unzippedFiles; }
From source file:Main.java
public static String[] getXmlFiles(String path) { List<String> xmlFiles = new ArrayList<>(); ZipFile zipFile = null;//from w ww .j av a2 s . c o m try { zipFile = new ZipFile(path); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); if (name.endsWith(".xml") && !name.equals("AndroidManifest.xml")) { xmlFiles.add(name); } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException ignored) { } } } Collections.sort(xmlFiles); return xmlFiles.toArray(new String[xmlFiles.size()]); }
From source file:com.ironiacorp.persistence.SqlUtil.java
/** * Check if the database driver is loaded. * /* ww w . j a v a 2 s .co m*/ * @return True if the driver is loaded, False otherwise. */ public static boolean isDriverLoaded(String driver) { // Check if the driver has been already loaded Enumeration<Driver> drivers = DriverManager.getDrivers(); while (drivers.hasMoreElements()) { Driver d = drivers.nextElement(); if (d.getClass().getName().equals(driver)) { return true; } } return false; }
From source file:de.nx42.maps4cim.util.Compression.java
/** * Reads the first file entry in a zip file and writes it in uncompressed * form to the desired file.// www . j av a 2s.com * @param zipFile the zip file to read from * @param dest the file to write the first zip file entry to * @return same as destination * @throws IOException if there is an error accessing the zip file or the * destination file */ public static File readFirstZipEntry(File zipFile, File dest) throws IOException { // open zip and get first entry ZipFile zf = new ZipFile(zipFile); Enumeration<ZipArchiveEntry> entries = zf.getEntries(); ZipArchiveEntry entry = entries.nextElement(); // write to file InputStream in = zf.getInputStream(entry); OutputStream out = new FileOutputStream(dest); ByteStreams.copy(in, out); // close all streams and return the new file in.close(); out.close(); zf.close(); return dest; }
From source file:Main.java
public static Collection<?> list(final Enumeration<?> e) { final ArrayList<Object> l = new ArrayList<Object>(); if (e != null) { while (e.hasMoreElements()) { final Object object = e.nextElement(); if (object != null) { l.add(object);/*from w ww . j av a 2 s . c o m*/ } } } return l; }