List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:com.mc.printer.model.utils.ZipHelper.java
/** * jar????/*from w w w .j a v a 2 s. com*/ * * @param jar ????jar * @param subDir jar??????? * @param loc ???? * @param force ???? * @return */ public static boolean unZip(String jar, String subDir, String loc, boolean force) { try { File base = new File(loc); if (!base.exists()) { base.mkdirs(); } ZipFile zip = new ZipFile(new File(jar)); Enumeration<? extends ZipEntry> entrys = zip.entries(); while (entrys.hasMoreElements()) { ZipEntry entry = entrys.nextElement(); String name = entry.getName(); if (!name.startsWith(subDir)) { continue; } //subDir name = name.replace(subDir, "").trim(); if (name.length() < 2) { log.debug(name + " < 2"); continue; } if (entry.isDirectory()) { File dir = new File(base, name); if (!dir.exists()) { dir.mkdirs(); log.debug("create directory"); } else { log.debug("the directory is existing."); } log.debug(name + " is a directory"); } else { File file = new File(base, name); if (file.exists() && force) { file.delete(); } if (!file.exists()) { InputStream in = zip.getInputStream(entry); FileUtils.copyInputStreamToFile(in, file); log.debug("create file."); in.close(); } else { log.debug("the file is existing"); } log.debug(name + " is not a directory"); } } zip.close(); } catch (ZipException ex) { ex.printStackTrace(); log.error("file unzip failed.", ex); return false; } catch (IOException ex) { ex.printStackTrace(); log.error("file IO failed", ex); return false; } return true; }
From source file:Main.java
public static String GetIPAdresses_JAVA() { String allIPAdresses = ""; Enumeration<NetworkInterface> e = null; try {/*from w w w .ja v a 2 s.c o m*/ e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); } if (e != null) { while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); allIPAdresses += (i.getHostAddress() + "\n"); } } } return allIPAdresses; }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the init parameters for a {@link javax.servlet.ServletConfig} object as a Map, preserving the order in which they are exposed * by the {@link javax.servlet.ServletConfig} object. *//*from www . j ava 2s.com*/ public static LinkedHashMap<String, String> initParametersToMap(ServletConfig config) { LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>(); Enumeration parameterNames = config.getInitParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); initParameters.put(parameterName, config.getInitParameter(parameterName)); } return initParameters; }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the init parameters for a {@link javax.servlet.FilterConfig} object as a Map, preserving the order in which they are exposed * by the {@link javax.servlet.FilterConfig} object. *///from w w w . jav a 2s .co m public static LinkedHashMap<String, String> initParametersToMap(FilterConfig config) { LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>(); Enumeration parameterNames = config.getInitParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); initParameters.put(parameterName, config.getInitParameter(parameterName)); } return initParameters; }
From source file:net.big_oh.common.web.WebUtil.java
/** * //from www . j a v a 2s . c o m * Calculate an <b>approximation</b> of the memory consumed by the objects * stored under each attribute of a user's {@link HttpSession}. The estimate * will often be greater than the actual value because of "double counting" * objects that appear multiple times in the attribute value's object graph. * * @param session * An HttpSession object from any web application. * @return An <b>approximation</b> of the memory consumed for each attribute * <b>name</b> in the session. */ public static Map<String, Integer> getSessionAttributeNameToApproxSizeInBytesMap(HttpSession session) { // Use an IdentityHashMap because we don't want to miss distinct objects // that are equivalent according to equals(..) method. Map<String, Integer> sessionAttributeNameToApproxSizeInBytesMap = new IdentityHashMap<String, Integer>(); Enumeration<?> enumeration = session.getAttributeNames(); while (enumeration.hasMoreElements()) { String attributeName = (String) enumeration.nextElement(); session.getAttribute(attributeName); try { sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(approximateObjectSize(attributeName))); } catch (IOException ioe) { logger.error("Failed to approximate size of session attribute name: " + attributeName.getClass().getName(), ioe); sessionAttributeNameToApproxSizeInBytesMap.put(attributeName, new Integer(0)); } } return sessionAttributeNameToApproxSizeInBytesMap; }
From source file:ReflectUtils.java
/** * Scans all classes accessible from the context class loader which belong to the given package and subpackages. * * @param packageName The base package//from ww w. j a v a2 s . c o m * @return The classes * @throws ClassNotFoundException * @throws IOException */ private static Class[] getClasses(String packageName) throws ClassNotFoundException, IOException { // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassLoader classLoader = ClassLoader.getSystemClassLoader(); assert classLoader != null; String path = packageName.replace('.', '/'); Enumeration<URL> resources = classLoader.getResources(path); List<File> dirs = new ArrayList<File>(); while (resources.hasMoreElements()) { URL resource = resources.nextElement(); dirs.add(new File(resource.getFile())); } ArrayList<Class> classes = new ArrayList<Class>(); for (File directory : dirs) { classes.addAll(findClasses(directory, packageName)); } return classes.toArray(new Class[classes.size()]); }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * @param request/*from www .ja v a 2 s .c o m*/ */ public static void printRequestParameters(final HttpServletRequest request) { log.debug("Request parameters:"); final Enumeration<?> parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { final String name = (String) parameterNames.nextElement(); log.debug(name + " = " + request.getParameter(name)); } }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * @param request//from w w w. j a v a2 s . com */ public static void printRequestAttributes(final HttpServletRequest request) { log.debug("Request attributes:"); final Enumeration<?> attributeNames = request.getAttributeNames(); while (attributeNames.hasMoreElements()) { final String name = (String) attributeNames.nextElement(); log.debug(name + " = " + request.getAttribute(name)); } }
From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java
/** * Create a chart representing an arbitrary collection of name/value pairs. * The data is passed in as a hashtable where the key is the name and the * value is the number items. /*from w ww. ja v a 2s . c o m*/ */ public static final JFreeChart getBarChart(Hashtable<String, Integer> data, String title, String nameLabel, String valueLabel) { JFreeChart chart = null; // Sort the data by name Vector<String> names = new Vector<String>(); Enumeration nameList = data.keys(); while (nameList.hasMoreElements()) { names.add((String) nameList.nextElement()); } Collections.sort(names); // Populate the dataset with data DefaultCategoryDataset dataset = new DefaultCategoryDataset(); Iterator keyIter = names.iterator(); while (keyIter.hasNext()) { String name = (String) keyIter.next(); Integer value = data.get(name); dataset.addValue(value, valueLabel, name); } // Create the chart chart = ChartFactory.createBarChart(title, /*title*/ nameLabel, /*categoryAxisLabel*/ valueLabel, /*valueAxisLabel*/ dataset, /*dataset*/ PlotOrientation.VERTICAL, /*orientation*/ false, /*legend*/ false, /*tooltips*/ false /*urls*/ ); // get a reference to the plot for further customization... CategoryPlot plot = (CategoryPlot) chart.getPlot(); //chartFormatter.formatMetricChart(plot, "min"); // Set the chart colors plot.setBackgroundPaint(Color.white); plot.setDomainGridlinePaint(Color.lightGray); plot.setRangeGridlinePaint(Color.lightGray); // set the range axis to display integers only... NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); renderer.setShadowVisible(false); final GradientPaint gp = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.blue); renderer.setSeriesPaint(0, gp); // Set the label orientation CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); return chart; }
From source file:org.sakuli.actions.environment.CipherUtil.java
/** * Determines a valid network interfaces. * * @return ethernet interface name/*from w ww .j a v a2 s . c om*/ * @throws Exception */ static String autodetectValidInterfaceName() throws Exception { Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface anInterface = interfaces.nextElement(); if (anInterface.getHardwareAddress() != null && anInterface.getHardwareAddress().length == 6) { return anInterface.getName(); } } throw new Exception("No network interface with a MAC address is present, please check your os settings!"); }