List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:edu.stanford.muse.util.Log4JUtils.java
/** taken from: http://stackoverflow.com/questions/3060240/how-do-you-flush-a-buffered-log4j-fileappender */ public static void flushAllLogs() { try {// w ww.ja va 2 s . com Set<FileAppender> flushedFileAppenders = new LinkedHashSet<FileAppender>(); Enumeration currentLoggers = LogManager.getLoggerRepository().getCurrentLoggers(); while (currentLoggers.hasMoreElements()) { Object nextLogger = currentLoggers.nextElement(); if (nextLogger instanceof Logger) { Logger currentLogger = (Logger) nextLogger; Enumeration allAppenders = currentLogger.getAllAppenders(); while (allAppenders.hasMoreElements()) { Object nextElement = allAppenders.nextElement(); if (nextElement instanceof FileAppender) { FileAppender fileAppender = (FileAppender) nextElement; if (!flushedFileAppenders.contains(fileAppender) && !fileAppender.getImmediateFlush()) { flushedFileAppenders.add(fileAppender); //log.info("Appender "+fileAppender.getName()+" is not doing immediateFlush "); fileAppender.setImmediateFlush(true); currentLogger .info("Flushing appender: " + fileAppender.getName() + "\n" + fileAppender); fileAppender.setImmediateFlush(false); } else { //log.info("fileAppender"+fileAppender.getName()+" is doing immediateFlush"); } } } } } } catch (RuntimeException e) { log.error("Failed flushing logs", e); } }
From source file:com.glaf.core.config.CustomProperties.java
public static void reload() { if (!loading.get()) { InputStream inputStream = null; try {/*w ww . j a v a 2 s .com*/ loading.set(true); String config = SystemProperties.getConfigRootPath() + "/conf/props"; logger.debug(config); File directory = new File(config); if (directory.exists()) { String[] filelist = directory.list(); if (filelist != null) { for (int i = 0, len = filelist.length; i < len; i++) { String filename = config + "/" + filelist[i]; logger.debug(filename); File file = new File(filename); if (file.isFile() && file.getName().endsWith(".properties")) { logger.info("load properties:" + file.getAbsolutePath()); inputStream = new FileInputStream(file); Properties p = PropertiesUtils.loadProperties(inputStream); if (p != null) { Enumeration<?> e = p.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = p.getProperty(key); properties.setProperty(key, value); properties.setProperty(key.toLowerCase(), value); properties.setProperty(key.toUpperCase(), value); } } IOUtils.closeStream(inputStream); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { loading.set(false); IOUtils.closeStream(inputStream); } } }
From source file:net.big_oh.common.web.WebUtil.java
/** * A convenience method that performs a reverse lookup to find all names * under which an attribute is stored in a user's {@link HttpSession}. * /* w w w . ja va 2 s . c o m*/ * @param session * An HttpSession object from any web application. * @param sessionAttribute * Attribute name of interest. * @return A seet of all attribute names under which the sessionAttribute * parameter is stored in the session. */ public static Set<String> getNamesForSessionAttribute(HttpSession session, Object sessionAttribute) { Set<String> attributeNames = new HashSet<String>(); Enumeration<?> attributeEnum = session.getAttributeNames(); while (attributeEnum.hasMoreElements()) { String attributeName = (String) attributeEnum.nextElement(); if (sessionAttribute == session.getAttribute(attributeName)) { attributeNames.add(attributeName); } } return attributeNames; }
From source file:Main.java
public static NetworkInterface getActiveNetworkInterface() { Enumeration<NetworkInterface> interfaces = null; try {/* w w w.j ava2 s.c om*/ interfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } while (interfaces.hasMoreElements()) { NetworkInterface iface = interfaces.nextElement(); Enumeration<InetAddress> inetAddresses = iface.getInetAddresses(); /* Check if we have a non-local address. If so, this is the active * interface. * * This isn't a perfect heuristic: I have devices which this will * still detect the wrong interface on, but it will handle the * common cases of wifi-only and Ethernet-only. */ if (iface.getName().startsWith("w")) { //this is a perfect hack for getting wifi alone while (inetAddresses.hasMoreElements()) { InetAddress addr = inetAddresses.nextElement(); if (!(addr.isLoopbackAddress() || addr.isLinkLocalAddress())) { Log.d("LSSDP", "DisplayName" + iface.getDisplayName() + " Name " + iface.getName()); return iface; } } } } return null; }
From source file:net.siegmar.japtproxy.JaptProxyServlet.java
/** * Logs the header of the incoming request. * * @param req the HttpServletRequest object *//*from ww w. j ava 2s . co m*/ private static void logHeader(final HttpServletRequest req) { final Enumeration<String> headers = req.getHeaderNames(); final StringBuilder sb = new StringBuilder(); while (headers.hasMoreElements()) { final String headerName = headers.nextElement(); sb.append(headerName); sb.append('='); sb.append(req.getHeader(headerName)); if (headers.hasMoreElements()) { sb.append(','); } } LOG.debug("Request header: {}", sb); }
From source file:info.dolezel.fatrat.plugins.helpers.NativeHelpers.java
private static Set<Class> findClasses(File directory, String packageName, Class annotation) throws ClassNotFoundException, IOException { Set<Class> classes = new HashSet<Class>(); if (!directory.exists()) { String fullPath = directory.toString(); String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); JarFile jarFile = new JarFile(jarPath); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); String entryName = entry.getName(); if (entryName.endsWith(".class") && !entryName.contains("$")) { String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); Class cls = loader.loadClass(className); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls);//from w ww . j av a2 s. co m } } } else { File[] files = directory.listFiles(); for (File file : files) { if (file.isDirectory()) { assert !file.getName().contains("."); classes.addAll(findClasses(file, packageName + "." + file.getName(), annotation)); } else if (file.getName().endsWith(".class")) { Class cls = loader.loadClass( packageName + '.' + file.getName().substring(0, file.getName().length() - 6)); if (annotation == null || cls.isAnnotationPresent(annotation)) classes.add(cls); } } } return classes; }
From source file:aiai.apps.commons.utils.ZipUtils.java
/** * Unzips a zip file into the given destination directory. * * The archive file MUST have a unique "root" folder. This root folder is * skipped when unarchiving.//from w ww .j a v a2 s . co m * */ public static void unzipFolder(File archiveFile, File zipDestinationFolder) { log.debug("Start unzipping archive file"); log.debug("'\tzip archive file: {}", archiveFile.getAbsolutePath()); log.debug("'\t\tis exist: {}", archiveFile.exists()); log.debug("'\t\tis writable: {}", archiveFile.canWrite()); log.debug("'\t\tis readable: {}", archiveFile.canRead()); log.debug("'\ttarget dir: {}", zipDestinationFolder.getAbsolutePath()); log.debug("'\t\tis exist: {}", zipDestinationFolder.exists()); log.debug("'\t\tis writable: {}", zipDestinationFolder.canWrite()); try (MyZipFile zipFile = new MyZipFile(archiveFile)) { Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry zipEntry = entries.nextElement(); log.debug("'\t\tzip entry: {}, is directory: {}", zipEntry.getName(), zipEntry.isDirectory()); String name = zipEntry.getName(); if (zipEntry.isDirectory()) { if (name.endsWith("/") || name.endsWith("\\")) { name = name.substring(0, name.length() - 1); } File newDir = new File(zipDestinationFolder, name); log.debug("'\t\t\tcreate dirs in {}", newDir.getAbsolutePath()); if (!newDir.mkdirs()) { throw new RuntimeException("Creation of target dir was failed, target dir: " + zipDestinationFolder + ", entity: " + name); } } else { File destinationFile = DirUtils.createTargetFile(zipDestinationFolder, name); if (destinationFile == null) { throw new RuntimeException("Creation of target file was failed, target dir: " + zipDestinationFolder + ", entity: " + name); } if (!destinationFile.getParentFile().exists()) { destinationFile.getParentFile().mkdirs(); } log.debug("'\t\t\tcopy content of zip entry to file {}", destinationFile.getAbsolutePath()); FileUtils.copyInputStreamToFile(zipFile.getInputStream(zipEntry), destinationFile); } } } catch (IOException e) { throw new RuntimeException("Unzip failed:", e); } }
From source file:com.salas.bb.utils.xml.XmlReaderFactory.java
/** * Reads properties from the resource into the map. Each key in properties resource * is a value for comma-delimetered list of keys. * * @param propertiesName name of properties resource. * * @return map./*from www . j a v a 2s . c o m*/ * * @throws IOException in case of I/O error. */ static Map readPropsToMap(String propertiesName) throws IOException { Properties props = new Properties(); props.load(XmlReaderFactory.class.getClassLoader().getResourceAsStream(propertiesName)); Map map = new HashMap(); Enumeration propEnumeration = props.propertyNames(); while (propEnumeration.hasMoreElements()) { String readerClassName = ((String) propEnumeration.nextElement()).trim(); String[] encodings = StringUtils.split(props.getProperty(readerClassName), ","); putKeysInMap(map, encodings, readerClassName); } return map; }
From source file:com.ai.smart.common.helper.util.RequestUtils.java
private static Map<String, String> getRequestMap(HttpServletRequest request, String prefix, boolean nameWithPrefix) { Map<String, String> map = new HashMap<String, String>(); Enumeration<String> names = request.getParameterNames(); String name, key, value;/*from ww w . j a v a 2 s . c o m*/ while (names.hasMoreElements()) { name = names.nextElement(); if (name.startsWith(prefix)) { key = nameWithPrefix ? name : name.substring(prefix.length()); value = StringUtils.join(request.getParameterValues(name), ','); map.put(key, value); } } return map; }
From source file:com.glaf.core.xml.XmlProperties.java
public static void reload() { if (!loading.get()) { InputStream inputStream = null; try {/* ww w . j a va 2 s.co m*/ loading.set(true); String config = SystemProperties.getConfigRootPath() + "/conf/templates/xml"; File directory = new File(config); if (directory.exists() && directory.isDirectory()) { String[] filelist = directory.list(); if (filelist != null) { for (int i = 0, len = filelist.length; i < len; i++) { String filename = config + "/" + filelist[i]; File file = new File(filename); if (file.isFile() && file.getName().endsWith(".properties")) { inputStream = new FileInputStream(file); Properties p = PropertiesUtils.loadProperties(inputStream); if (p != null) { Enumeration<?> e = p.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = p.getProperty(key); properties.setProperty(key, value); properties.setProperty(key.toLowerCase(), value); properties.setProperty(key.toUpperCase(), value); } } IOUtils.closeStream(inputStream); } } } } } catch (Exception ex) { throw new RuntimeException(ex); } finally { loading.set(false); IOUtils.closeStream(inputStream); } } }