List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:org.paxml.bean.UnzipTag.java
public static void unzip(File file, File dir) { dir.mkdirs();/*from w w w. ja v a 2 s . c o m*/ ZipFile zipFile = null; try { zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { new File(dir, entry.getName()).mkdirs(); continue; } InputStream in = null; OutputStream out = null; try { zipFile.getInputStream(entry); out = new BufferedOutputStream(new FileOutputStream(entry.getName())); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } catch (IOException ioe) { throw new PaxmlRuntimeException( "Cannot unzip file: " + file.getAbsolutePath() + " under dir: " + dir.getAbsolutePath(), ioe); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // do nothing } } } }
From source file:Main.java
public static int upZipFile(File zipFile, String folderPath) throws IOException { ZipFile zfile = new ZipFile(zipFile); Enumeration zList = zfile.entries(); ZipEntry ze = null;/*from w w w .ja v a 2 s . c om*/ byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { String dirstr = folderPath + ze.getName(); dirstr = new String(dirstr.getBytes("8859_1"), "GB2312"); File f = new File(dirstr); f.mkdirs(); continue; } OutputStream os = new BufferedOutputStream( new FileOutputStream(getRealFileName(folderPath, ze.getName()))); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf, 0, 1024)) != -1) { os.write(buf, 0, readLen); } is.close(); os.close(); } zfile.close(); return 0; }
From source file:org.ambraproject.wombat.util.ReproxyUtil.java
/** * Check whether a request supports reproxying. * * @param request a request//from w w w. ja va 2s.co m * @return {@code true} if it supports reproxying */ private static boolean supportsReproxy(HttpServletRequest request) { Enumeration headers = request.getHeaders(X_PROXY_CAPABILITIES); if (headers != null) { while (headers.hasMoreElements()) { if (REPROXY_FILE.equals(headers.nextElement())) { return true; } } } return false; }
From source file:ke.alphacba.cms.core.util.RequestUtils.java
/** * ????Map./*from w w w. ja v a 2s .c om*/ * * @param request * @return */ public static Map<String, String> getParamMap(HttpServletRequest request) { Map<String, String> paramMap = new HashMap<String, String>(); Enumeration<String> enume = request.getParameterNames(); while (enume.hasMoreElements()) { String paramName = enume.nextElement(); paramMap.put(paramName, request.getParameter(paramName)); } return paramMap; }
From source file:Main.java
/** * Given an Object, and a key (index), it will get value associated with * that key in the Object. The following checks are made: * <ul>// www . j ava 2 s . c om * <li>If obj is a Map, use the index as a key to get a value. If no match * continue. * <li>Check key is an Integer. If not, return the object passed in. * <li>If obj is a Map, get the nth value from the <b>key</b> iterator. * <li>If obj is a List or an array, get the nth value. * <li>If obj is an iterator, enumeration or Collection, get the nth value * from the iterator. * <li>Return the original obj. * </ul> * * @param obj * the object to get an index of * @param index * the index to get * @return the object at the specified index * @throws IndexOutOfBoundsException * @throws NoSuchElementException */ public static Object index(Object obj, Object index) { if (obj instanceof Map) { Map map = (Map) obj; if (map.containsKey(index)) { return map.get(index); } } int idx = -1; if (index instanceof Integer) { idx = ((Integer) index).intValue(); } if (idx < 0) { return obj; } else if (obj instanceof Map) { Map map = (Map) obj; Iterator iterator = map.keySet().iterator(); return index(iterator, idx); } else if (obj instanceof List) { return ((List) obj).get(idx); } else if (obj instanceof Object[]) { return ((Object[]) obj)[idx]; } else if (obj instanceof Enumeration) { Enumeration enumeration = (Enumeration) obj; while (enumeration.hasMoreElements()) { idx--; if (idx == -1) { return enumeration.nextElement(); } else { enumeration.nextElement(); } } } else if (obj instanceof Iterator) { return index((Iterator) obj, idx); } else if (obj instanceof Collection) { Iterator iterator = ((Collection) obj).iterator(); return index(iterator, idx); } return obj; }
From source file:com.ephesoft.dcma.util.NetworkUtil.java
/** * Utility method which will fetch the ip address of the system. * //from w w w . ja v a2 s . c o m * @return ip address of the system. */ public static String getSystemIPAddress() { StringBuilder input = new StringBuilder(UtilConstants.INPUT_CONST); boolean first = true; String returnAddress = null; try { for (Enumeration<NetworkInterface> enumer = NetworkInterface.getNetworkInterfaces(); enumer .hasMoreElements();) { NetworkInterface netInterface = enumer.nextElement(); Enumeration<InetAddress> inetEnum = netInterface.getInetAddresses(); while (inetEnum.hasMoreElements()) { InetAddress inetAddress = inetEnum.nextElement(); if (!inetAddress.isLoopbackAddress()) { if (first) { first = false; } else { input.append(UtilConstants.FORWARD_SLASH); } input.append(inetAddress.getHostAddress()); } } } } catch (Exception e) { LOG.error(e.getMessage(), e); returnAddress = IPADDRESS; } if (null == returnAddress) { returnAddress = first ? IPADDRESS : input.toString(); } return returnAddress; }
From source file:io.apiman.servers.gateway_h2.Starter.java
/** * Loads properties from a file and puts them into system properties. *//* w w w. j av a 2 s. c o m*/ @SuppressWarnings({ "unchecked" }) protected static void loadProperties() { URL configUrl = Starter.class.getClassLoader().getResource("gateway_h2-apiman.properties"); if (configUrl == null) { throw new RuntimeException( "Failed to find properties file (see README.md): gateway_h2-apiman.properties"); } InputStream is = null; try { is = configUrl.openStream(); Properties props = new Properties(); props.load(is); Enumeration<String> names = (Enumeration<String>) props.propertyNames(); while (names.hasMoreElements()) { String name = names.nextElement(); String value = props.getProperty(name); System.setProperty(name, value); } } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } }
From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java
/** * @param path/*from w ww . jav a2s.c o m*/ * @param tmpWarDir * @throws IOException */ private static void copy(Enumeration<String> paths, File destDir) throws IOException { if (paths != null) { while (paths.hasMoreElements()) { String path = paths.nextElement(); if (path.endsWith("/")) { File targetDir = new File(destDir, FilenameUtils.getName(path.substring(0, path.lastIndexOf("/")))); copy(Activator.getContext().getBundle().getEntryPaths(path), targetDir); } else { URL entry = Activator.getContext().getBundle().getEntry(path); FileUtils.copyInputStreamToFile(entry.openStream(), new File(destDir, FilenameUtils.getName(path))); } } } }
From source file:Main.java
public static List<String> getDexEntries() { try {/*from w w w . j a va2 s . c om*/ Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null); Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app); Class<?> dexFileClass = Class.forName("dalvik.system.DexFile"); Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath); Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile); List<String> dexEntries = new LinkedList<>(); while (entries.hasMoreElements()) { String entry = entries.nextElement(); entry = entry.replace('.', '/') + ".class"; dexEntries.add(entry); } dexFileClass.getMethod("close").invoke(dexFile); return dexEntries; } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException e) { throw new RuntimeException(e); } }
From source file:cc.aileron.commons.util.ClassPattrnFinderUtils.java
/** * ??????/*from w w w.j a va 2 s . com*/ * * @param targetPackage * @param pattern * @return * @throws IOException * @throws URISyntaxException * @throws ResourceNotFoundException */ private static final List<Class<?>> tryGetClassNameList(final String targetPackage, final Pattern pattern) throws IOException, URISyntaxException, ResourceNotFoundException { final List<Class<?>> result = new ArrayList<Class<?>>(); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final String path = targetPackage.replace('.', '/') + "/"; final Enumeration<URL> urls = classLoader.getResources(path); while (urls.hasMoreElements()) { final URL url = urls.nextElement(); final Resource resource = ResourceConvertUtils.convertUrl(url); for (final FileObject file : resource.toFileObject().getChildren()) { final String name = file.getName().getBaseName().split("\\.")[0]; if (!file.getType().equals(FileType.FILE) || !file.getName().getExtension().equals("class")) { continue; } if (pattern != null && !pattern.matcher(name).matches()) { continue; } final Class<?> classObject = getClass(targetPackage + "." + name); if (classObject != null) { result.add(classObject); } } } return result; }