List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:NwFontChooserS.java
static public void setDefaultFont(Font f) { FontUIResource fui = new FontUIResource(f); Enumeration<Object> keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value instanceof FontUIResource) UIManager.put(key, fui); }/*w ww . j av a 2s . c om*/ }
From source file:Main.java
@SuppressWarnings("unchecked") public static <E> E[] toArray(Enumeration<E> enumeration, Class<E> type) { ArrayList<E> elements = new ArrayList<E>(); while (enumeration.hasMoreElements()) { elements.add(enumeration.nextElement()); }//from w w w . java2 s . co m E[] array = (E[]) Array.newInstance(type, elements.size()); elements.toArray(array); return array; }
From source file:com.icesoft.net.messaging.jms.AbstractJMSConnection.java
protected static String toString(final javax.jms.Message message) { StringBuffer _messageString = new StringBuffer(); try {/*from ww w. j a va 2 s . c om*/ Enumeration _propertyNames = message.getPropertyNames(); while (_propertyNames.hasMoreElements()) { String _propertyName = (String) _propertyNames.nextElement(); _messageString.append(_propertyName); _messageString.append(": "); _messageString.append(message.getObjectProperty(_propertyName)); _messageString.append("\r\n"); } _messageString.append("\r\n"); if (message instanceof javax.jms.ObjectMessage) { _messageString.append(((javax.jms.ObjectMessage) message).getObject()); } else if (message instanceof javax.jms.TextMessage) { _messageString.append(((javax.jms.TextMessage) message).getText()); } _messageString.append("\r\n"); } catch (JMSException exception) { // do nothing (this is just a toString() method) } return _messageString.toString(); }
From source file:eu.morfeoproject.fast.catalogue.util.Util.java
/** * @return the list of values associated with a header. Never null. *///from w w w . java 2 s. c o m public static List<String> getHeader(HttpServletRequest request, String hname) { List<String> values = new ArrayList<String>(); Enumeration<?> hvals = request.getHeaders(hname.toString()); while (hvals.hasMoreElements()) { String hval = String.valueOf(hvals.nextElement()); values.add(hval); } return values; }
From source file:com.cisco.dbds.utils.configfilehandler.ConfigFileHandler.java
/** * Load jar cong file.//ww w . java2 s . c om * * @param Utilclass the utilclass */ public static void loadJarCongFile(Class Utilclass) { try { String path = Utilclass.getResource("").getPath(); path = path.substring(6, path.length() - 1); path = path.split("!")[0]; System.out.println(path); JarFile jarFile = new JarFile(path); final Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { final JarEntry entry = entries.nextElement(); if (entry.getName().contains(".properties")) { System.out.println("Jar File Property File: " + entry.getName()); JarEntry fileEntry = jarFile.getJarEntry(entry.getName()); InputStream input = jarFile.getInputStream(fileEntry); setSystemvariable(input); InputStreamReader isr = new InputStreamReader(input); BufferedReader reader = new BufferedReader(isr); String line; while ((line = reader.readLine()) != null) { System.out.println("Jar file" + line); } reader.close(); } } jarFile.close(); } catch (Exception e) { System.out.println("Jar file reading Error"); } }
From source file:edu.stanford.muse.util.Log4JUtils.java
/** adds a new file appender to the root logger. expects root logger to have at least a console appender from which it borrows the layout */ private static void addLogFileAppender(String filename) { try {/*w w w . ja v a2 s.com*/ Logger rootLogger = LogManager.getLoggerRepository().getRootLogger(); Enumeration allAppenders = rootLogger.getAllAppenders(); while (allAppenders.hasMoreElements()) { Object next = allAppenders.nextElement(); if (next instanceof ConsoleAppender) { Layout layout = ((ConsoleAppender) next).getLayout(); RollingFileAppender rfa = new RollingFileAppender(layout, filename); rfa.setMaxFileSize("10MB"); rfa.setMaxBackupIndex(10); // do we rfa.setEncoding("UTF-8"); rootLogger.addAppender(rfa); } } } catch (Exception e) { log.error("Failed creating log appender in " + filename); System.err.println("Failed creating log appender in " + filename); } }
From source file:io.fabric8.vertx.maven.plugin.utils.WebJars.java
/** * Checks whether the given file is a WebJar or not (http://www.webjars.org/documentation). * The check is based on the presence of {@literal META-INF/resources/webjars/} directory in the jar file. * * @param file the file./* w ww. j a v a2 s.c o m*/ * @return {@literal true} if it's a bundle, {@literal false} otherwise. */ public static boolean isWebJar(Log log, File file) { if (file == null) { return false; } Set<String> found = new LinkedHashSet<>(); if (file.isFile() && file.getName().endsWith(".jar")) { JarFile jar = null; try { jar = new JarFile(file); // Fast return if the base structure is not there if (jar.getEntry(WEBJAR_LOCATION) == null) { return false; } Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher matcher = WEBJAR_REGEX.matcher(entry.getName()); if (matcher.matches()) { found.add(matcher.group(1) + "-" + matcher.group(2)); } } } catch (IOException e) { log.error("Cannot check if the file " + file.getName() + " is a webjar, cannot open it", e); return false; } finally { final JarFile finalJar = jar; IOUtils.closeQuietly(() -> { if (finalJar != null) { finalJar.close(); } }); } for (String lib : found) { log.info("Web Library found in " + file.getName() + " : " + lib); } return !found.isEmpty(); } return false; }
From source file:Main.java
public static void unzip(String strZipFile) { try {//from w w w .j ava 2 s . c om /* * STEP 1 : Create directory with the name of the zip file * * For e.g. if we are going to extract c:/demo.zip create c:/demo directory where we can extract all the zip entries */ File fSourceZip = new File(strZipFile); String zipPath = strZipFile.substring(0, strZipFile.length() - 4); File temp = new File(zipPath); temp.mkdir(); System.out.println(zipPath + " created"); /* * STEP 2 : Extract entries while creating required sub-directories */ ZipFile zipFile = new ZipFile(fSourceZip); Enumeration<? extends ZipEntry> e = zipFile.entries(); while (e.hasMoreElements()) { ZipEntry entry = (ZipEntry) e.nextElement(); File destinationFilePath = new File(zipPath, entry.getName()); // create directories if required. destinationFilePath.getParentFile().mkdirs(); // if the entry is directory, leave it. Otherwise extract it. if (entry.isDirectory()) { continue; } else { // System.out.println("Extracting " + destinationFilePath); /* * Get the InputStream for current entry of the zip file using * * InputStream getInputStream(Entry entry) method. */ BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); int b; byte buffer[] = new byte[1024]; /* * read the current entry from the zip file, extract it and write the extracted file. */ FileOutputStream fos = new FileOutputStream(destinationFilePath); BufferedOutputStream bos = new BufferedOutputStream(fos, 1024); while ((b = bis.read(buffer, 0, 1024)) != -1) { bos.write(buffer, 0, b); } // flush the output stream and close it. bos.flush(); bos.close(); // close the input stream. bis.close(); } } zipFile.close(); } catch (IOException ioe) { System.out.println("IOError :" + ioe); } }
From source file:com.scf.core.context.app.cfg.module.ModuleConfigHandler.java
/** * marges props/*from w w w.ja v a2 s . c o m*/ * * @param marges * @param moduleName * @param props * @return */ @SuppressWarnings("rawtypes") private static ConfigParams loadModuleConfig(Properties marges, String moduleName, Properties props) { if (marges != null) { Enumeration pks = marges.propertyNames(); while (pks.hasMoreElements()) { String pk = (String) pks.nextElement(); String _pk = "module_" + moduleName + "."; if (pk.startsWith(_pk)) { _pk = pk.substring(_pk.length()); _logger.info("Module config override " + pk + " = " + marges.getProperty(pk) + "[default: " + props.getProperty(_pk) + "]"); props.setProperty(_pk, marges.getProperty(pk)); } } } ConfigParams cp = new ConfigParams(); cp.setParams(props); return cp; }
From source file:kilim.tools.FlowAnalyzer.java
public static void analyzeJar(String jarFile, Detector detector) { try {//from ww w. j av a 2s.co m Enumeration<JarEntry> e = new JarFile(jarFile).entries(); while (e.hasMoreElements()) { ZipEntry en = (ZipEntry) e.nextElement(); String n = en.getName(); if (!n.endsWith(".class")) continue; n = n.substring(0, n.length() - 6).replace('/', '.'); analyzeClass(n, detector); } } catch (Exception e) { e.printStackTrace(); } }