List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); DefaultStyledDocument doc = (DefaultStyledDocument) textPane.getDocument(); Enumeration e1 = doc.getStyleNames(); while (e1.hasMoreElements()) { String styleName = (String) e1.nextElement(); System.out.println(styleName); Style style = doc.getStyle(styleName); int count = style.getAttributeCount(); System.out.println(count); Enumeration e = style.getAttributeNames(); while (e.hasMoreElements()) { Object o = e.nextElement(); if (o instanceof String) { String attrName = (String) o; Object attrValue = style.getAttribute(attrName); System.out.println(attrValue); } else if (o == StyleConstants.NameAttribute) { styleName = (String) style.getAttribute(o); System.out.println(styleName); } else if (o == StyleConstants.ResolveAttribute) { Style parent = (Style) style.getAttribute(o); System.out.println(parent.getName()); } else { String attrName = o.toString(); System.out.println(attrName); Object attrValue = style.getAttribute(o); System.out.println(attrValue); }/*from w ww.j av a 2s. c om*/ } } }
From source file:MainClass.java
public static void main(String[] ap) { Enumeration pList = CommPortIdentifier.getPortIdentifiers(); while (pList.hasMoreElements()) { CommPortIdentifier cpi = (CommPortIdentifier) pList.nextElement(); System.out.print("Port " + cpi.getName() + " "); if (cpi.getPortType() == CommPortIdentifier.PORT_SERIAL) { System.out.println("is a Serial Port: " + cpi); } else if (cpi.getPortType() == CommPortIdentifier.PORT_PARALLEL) { System.out.println("is a Parallel Port: " + cpi); } else {// ww w.ja va 2s . c o m System.out.println("is an Unknown Port: " + cpi); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); printParameter(ni);//from ww w.java2s .c om } }
From source file:NetworkParameterDemo.java
public static void main(String[] args) throws Exception { Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface ni = en.nextElement(); printParameter(ni);/*from w ww.j a va2 s .c o m*/ } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { URLName server = new URLName("protocol://username@host/foldername"); Session session = Session.getDefaultInstance(new Properties(), new MailAuthenticator()); Folder folder = session.getFolder(server); if (folder != null) { folder.open(Folder.READ_ONLY);/* w w w. j a va 2 s .c o m*/ Message[] messages = folder.getMessages(); for (int i = 0; i < messages.length; i++) { System.out.println((i + 1)); Enumeration headers = messages[i].getAllHeaders(); while (headers.hasMoreElements()) { Header h = (Header) headers.nextElement(); System.out.println(h.getName() + ": " + h.getValue()); } } folder.close(false); } }
From source file:ListPorts.java
public static void main(String args[]) { Enumeration ports = CommPortIdentifier.getPortIdentifiers(); while (ports.hasMoreElements()) { CommPortIdentifier port = (CommPortIdentifier) ports.nextElement(); String type;/*w w w . j av a2 s. c o m*/ switch (port.getPortType()) { case CommPortIdentifier.PORT_PARALLEL: type = "Parallel"; break; case CommPortIdentifier.PORT_SERIAL: type = "Serial"; break; default: /// Shouldn't happen type = "Unknown"; break; } System.out.println(port.getName() + ": " + type); } }
From source file:HashtableDemo.java
public static void main(String[] argv) { // Construct and load the hash. This simulates loading a // database or reading from a file, or wherever the data is. Hashtable h = new Hashtable(); // The hash maps from company name to address. // In real life this might map to an Address object... h.put("Adobe", "Mountain View, CA"); h.put("IBM", "White Plains, NY"); h.put("Learning Tree", "Los Angeles, CA"); h.put("Microsoft", "Redmond, WA"); h.put("Netscape", "Mountain View, CA"); h.put("O'Reilly", "Sebastopol, CA"); h.put("Sun", "Mountain View, CA"); // Two versions of the "retrieval" phase. // Version 1: get one pair's value given its key // (presumably the key would really come from user input): String queryString = "O'Reilly"; System.out.println("You asked about " + queryString + "."); String resultString = (String) h.get(queryString); System.out.println("They are located in: " + resultString); System.out.println();//from ww w. j a v a2s . c o m // Version 2: get ALL the keys and pairs // (maybe to print a report, or to save to disk) Enumeration k = h.keys(); while (k.hasMoreElements()) { String key = (String) k.nextElement(); System.out.println("Key " + key + "; Value " + (String) h.get(key)); } }
From source file:MainClass.java
public static void main(String args[]) { Hashtable<String, Double> balance = new Hashtable<String, Double>(); Enumeration<String> names; String str;/*from w w w . j ava2 s . com*/ balance.put("A", 3434.34); names = balance.keys(); while (names.hasMoreElements()) { str = names.nextElement(); System.out.println(str + ": " + balance.get(str)); } System.out.println(); }
From source file:ZipCompress.java
public static void main(String[] args) throws IOException { FileOutputStream f = new FileOutputStream("test.zip"); CheckedOutputStream csum = new CheckedOutputStream(f, new Adler32()); ZipOutputStream zos = new ZipOutputStream(csum); BufferedOutputStream out = new BufferedOutputStream(zos); zos.setComment("A test of Java Zipping"); // No corresponding getComment(), though. for (int i = 0; i < args.length; i++) { System.out.println("Writing file " + args[i]); BufferedReader in = new BufferedReader(new FileReader(args[i])); zos.putNextEntry(new ZipEntry(args[i])); int c;// w ww.j a v a 2 s. com while ((c = in.read()) != -1) out.write(c); in.close(); } out.close(); // Checksum valid only after the file has been closed! System.out.println("Checksum: " + csum.getChecksum().getValue()); // Now extract the files: System.out.println("Reading file"); FileInputStream fi = new FileInputStream("test.zip"); CheckedInputStream csumi = new CheckedInputStream(fi, new Adler32()); ZipInputStream in2 = new ZipInputStream(csumi); BufferedInputStream bis = new BufferedInputStream(in2); ZipEntry ze; while ((ze = in2.getNextEntry()) != null) { System.out.println("Reading file " + ze); int x; while ((x = bis.read()) != -1) System.out.write(x); } System.out.println("Checksum: " + csumi.getChecksum().getValue()); bis.close(); // Alternative way to open and read zip files: ZipFile zf = new ZipFile("test.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze2 = (ZipEntry) e.nextElement(); System.out.println("File: " + ze2); // ... and extract the data as before } }
From source file:net.vnt.ussdapp.util.ContextTest.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "/context.xml" }); ContextProperties ctxProp = (ContextProperties) Context.getInstance().getBean("ContextProperties"); TXTParser parser = (TXTParser) Context.getInstance().getBean("TXTParser"); String mainmenu = ctxProp.getProperty("ussdapp.wrong"); try {/*from www . jav a2s. c o m*/ Vector<String> vs = parser.readFields(mainmenu); Enumeration<String> ens = vs.elements(); StringBuilder sb = new StringBuilder(); while (ens.hasMoreElements()) { sb.append(ens.nextElement()).append("\n"); } System.out.println(sb.toString()); } catch (IOException ex) { Logger.getLogger(ContextTest.class.getName()).log(Level.SEVERE, null, ex); } System.out.println(System.getProperty("os.arch")); }