Example usage for java.util Enumeration hasMoreElements

List of usage examples for java.util Enumeration hasMoreElements

Introduction

In this page you can find the example usage for java.util Enumeration hasMoreElements.

Prototype

boolean hasMoreElements();

Source Link

Document

Tests if this enumeration contains more elements.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Class driverClass = Class.forName("org.hsqldb.jdbcDriver");
    DriverManager.registerDriver((Driver) driverClass.newInstance());

    // Print out all loaded JDBC drivers.
    java.util.Enumeration e = java.sql.DriverManager.getDrivers();
    while (e.hasMoreElements()) {
        Object driverAsObject = e.nextElement();
        System.out.println("JDBC Driver=" + driverAsObject);
    }/*from w  ww  .j  a v  a  2 s . c  om*/

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream is = new FileInputStream("your.keystore");

    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    keystore.load(is, "my-keystore-password".toCharArray());

    Enumeration e = keystore.aliases();
    for (; e.hasMoreElements();) {
        String alias = (String) e.nextElement();

        java.security.cert.Certificate cert = keystore.getCertificate(alias);
        if (cert instanceof X509Certificate) {
            X509Certificate x509cert = (X509Certificate) cert;

            // Get subject
            Principal principal = x509cert.getSubjectDN();
            String subjectDn = principal.getName();

            // Get issuer
            principal = x509cert.getIssuerDN();
            String issuerDn = principal.getName();
        }//w ww  .j a  va  2 s  .c om
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String zipname = "data.zip";
    ZipFile zipFile = new ZipFile(zipname);
    Enumeration enumeration = zipFile.entries();
    while (enumeration.hasMoreElements()) {
        ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
        System.out.println("Unzipping: " + zipEntry.getName());
        BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
        int size;
        byte[] buffer = new byte[2048];
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(zipEntry.getName()),
                buffer.length);/*  ww w  .  j a  v  a  2 s.  c  o  m*/
        while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
            bos.write(buffer, 0, size);
        }
        bos.flush();
        bos.close();
        bis.close();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {

    JarFile jf = new JarFile(args[0]);
    Enumeration e = jf.entries();
    while (e.hasMoreElements()) {
        JarEntry je = (JarEntry) e.nextElement();
        String name = je.getName();
        Date lastModified = new Date(je.getTime());
        long uncompressedSize = je.getSize();
        long compressedSize = je.getCompressedSize();

        int method = je.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 {// w w  w .ja  v a  2 s.  c om
            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) + "%");
        }
    }
}

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 {/*from   w  w w .j  av a 2 s . c o m*/
            System.out.println("is an Unknown Port: " + cpi);
        }
    }
}

From source file:ArrayEnumerationFactory.java

public static void main(String args[]) {
    Enumeration e = makeEnumeration(args);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }/*from  www  .ja  va2  s. c o  m*/
    e = makeEnumeration(new int[] { 1, 3, 4, 5 });
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }
    try {
        e = makeEnumeration(new Double(Math.PI));
    } catch (IllegalArgumentException ex) {
        System.err.println("Can't enumerate that: " + ex.getMessage());
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();
    while (e.hasMoreElements()) {
        NetworkInterface nif = e.nextElement();
        System.out.println("Name: " + nif.getName() + ",  Supports Multicast: " + nif.supportsMulticast()
                + ", isUp(): " + nif.isUp());
    }/*from   w ww  .  j  a  v a  2  s .c  o  m*/
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    ZipFile zf = new ZipFile("a.zip");
    Enumeration e = zf.entries();
    while (e.hasMoreElements()) {
        ZipEntry ze = (ZipEntry) e.nextElement();
        String name = ze.getName();

        long uncompressedSize = ze.getSize();
        long compressedSize = ze.getCompressedSize();
        long crc = ze.getCrc();
        int method = ze.getMethod();
        String comment = ze.getComment();

        System.out.println(name + " was stored at " + new Date(ze.getTime()));
        if (method == ZipEntry.STORED) {
            System.out.println("with a size of  " + uncompressedSize + " bytes");
        } else if (method == ZipEntry.DEFLATED) {
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        } else {//from   ww  w.ja  v a2 s  . co  m
            System.out.println("from " + uncompressedSize + " bytes to " + compressedSize);
        }
        System.out.println("Its CRC is " + crc);
        if (comment != null && !comment.equals("")) {
            System.out.println(comment);
        }
        if (ze.isDirectory()) {
            System.out.println(name + " is a directory");
        }
    }
}

From source file:ArrayEnumeration.java

public static void main(String args[]) {
    Object obj = new int[] { 2, 3, 5, 8, 13, 21 };
    Enumeration e = new ArrayEnumeration(obj);
    while (e.hasMoreElements()) {
        System.out.println(e.nextElement());
    }//w ww .  ja  v a 2s .  c  o m
    try {
        e = new ArrayEnumeration("Not an Array");
    } catch (IllegalArgumentException ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:Main.java

public static void main(String args[]) {
    // create array list object       
    List<String> arrlist = new ArrayList<String>();

    // populate the list
    arrlist.add("A");
    arrlist.add("B");
    arrlist.add("from java2s.com");

    // create Enumeration
    Enumeration<String> e = Collections.enumeration(arrlist);

    while (e.hasMoreElements()) {
        System.out.println("Value is: " + e.nextElement());
    }//www  .  ja va  2 s  .  c  o m
}