List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
public static void main(String[] args) throws IOException { JarFile jf = new JarFile("a.jar"); Enumeration e = jf.entries(); while (e.hasMoreElements()) { JarEntry je = (JarEntry) e.nextElement(); System.out.println(je.getName()); long uncompressedSize = je.getSize(); long compressedSize = je.getCompressedSize(); long crc = je.getCrc(); int method = je.getMethod(); String comment = je.getComment(); System.out.println(new Date(je.getTime())); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize); if (method == ZipEntry.STORED) { System.out.println("ZipEntry.STORED"); } else if (method == ZipEntry.DEFLATED) { System.out.println(ZipEntry.DEFLATED); }//from www . j a v a 2 s .com System.out.println("Its CRC is " + crc); System.out.println(comment); System.out.println(je.isDirectory()); Attributes a = je.getAttributes(); if (a != null) { Object[] nameValuePairs = a.entrySet().toArray(); for (int j = 0; j < nameValuePairs.length; j++) { System.out.println(nameValuePairs[j]); } } System.out.println(); } }
From source file:MainResourceBundle.java
public static void main(String[] args) { // create a new ResourceBundle with specified locale ResourceBundle bundle = MainResourceBundle.getBundle("hello", Locale.US); // print the keys Enumeration<String> enumeration = bundle.getKeys(); while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); }//from ww w . ja va 2 s. c om }
From source file:MainClass.java
public static void main(String[] args) { try {/* www .j a va 2 s.c o m*/ ZipFile zf = new ZipFile("your.zip"); Enumeration e = zf.entries(); while (e.hasMoreElements()) { ZipEntry ze = (ZipEntry) e.nextElement(); String name = ze.getName(); Date lastModified = new Date(ze.getTime()); long uncompressedSize = ze.getSize(); long compressedSize = ze.getCompressedSize(); int method = ze.getMethod(); if (method == ZipEntry.STORED) { System.out.println(name + " was stored at " + lastModified); System.out.println("with a size of " + uncompressedSize + " bytes"); } else if (method == ZipEntry.DEFLATED) { System.out.println(name + " was deflated at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } else { System.out.println(name + " was compressed using an unrecognized method at " + lastModified); System.out.println("from " + uncompressedSize + " bytes to " + compressedSize + " bytes, a savings of " + (100.0 - 100.0 * compressedSize / uncompressedSize) + "%"); } } } catch (IOException ex) { System.err.println(ex); } }
From source file:OptionsMethodExample.java
public static void main(String args[]) { HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Test Client"); OptionsMethod method = new OptionsMethod("http://www.google.com"); try {// ww w .java 2 s . c o m int returnCode = client.executeMethod(method); Enumeration list = method.getAllowedMethods(); while (list.hasMoreElements()) { System.err.println(list.nextElement()); } } catch (Exception e) { System.err.println(e); } finally { method.releaseConnection(); } }
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 .ja v a 2 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:ArrayToVector.java
public static void main(String[] args) { Object[] a1d = { "Hello World", new Date(), Calendar.getInstance(), }; // Arrays.asList(Object[]) --> List List l = Arrays.asList(a1d); // Vector contstructor takes Collection // List is a subclass of Collection Vector v;//w w w .j a v a 2 s. c o m v = new Vector(l); // Or, more simply: v = new Vector(Arrays.asList(a1d)); // Just to prove that it worked. Enumeration e = v.elements(); while (e.hasMoreElements()) { System.out.println(e.nextElement()); } }
From source file:MyResources.java
public static void main(String[] args) { MyResources mr = new MyResources(); // get the keys Enumeration<String> enumeration = mr.getKeys(); // print the keys while (enumeration.hasMoreElements()) { System.out.println(enumeration.nextElement()); }// w w w . j a v a2s. c o m }
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); }/* w w w . j av a 2 s . co m*/ } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ZipFile zf = new ZipFile("a.zip"); Enumeration<? extends ZipEntry> files = zf.entries(); while (files.hasMoreElements()) { ZipEntry ze = files.nextElement(); System.out.println("Decompressing " + ze.getName()); System.out.println(/*from w ww . j av a2 s . co m*/ " Compressed Size: " + ze.getCompressedSize() + " Expanded Size: " + ze.getSize() + "\n"); BufferedInputStream fin = new BufferedInputStream(zf.getInputStream(ze)); BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(ze.getName())); int i; do { i = fin.read(); if (i != -1) fout.write(i); } while (i != -1); fout.close(); fin.close(); } zf.close(); }
From source file:IteratorEnumeration.java
public static void main(String[] args) { Set<String> set = new HashSet<String>(); set.add("a"); set.add("b"); set.add("c"); set.add("d"); Enumeration<String> x = new IteratorEnumeration<String>(set.iterator()); while (x.hasMoreElements()) { System.out.println(x.nextElement()); }// w ww. ja v a 2 s . c o m }