Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

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

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

From source file:com.twitter.ambrose.model.hadoop.MapReduceHelper.java

public static Configuration toConfiguration(Properties properties) {
    assert properties != null;
    final Configuration config = new Configuration(false);
    final Enumeration<Object> iter = properties.keys();
    while (iter.hasMoreElements()) {
        final String key = (String) iter.nextElement();
        final String val = properties.getProperty(key);
        config.set(key, val);
    }// w w  w .j ava 2s . com
    return config;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * //from  ww w .j  a  v a 2 s  .co m
 * @param collection
 *            the collection to add to, must not be null
 * @param enumeration
 *            the enumeration of elements to add, must not be null
 * @throws NullPointerException
 *             if the collection or enumeration is null
 */
public static <E> void addAll(Collection<E> collection, Enumeration<E> enumeration) {
    if (collection == null || enumeration == null) {
        return;
    }

    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }
}

From source file:com.microsoft.aad.adal4j.AsymmetricKeyCredential.java

/**
 * Static method to create KeyCredential instance.
 * /*from  w w w  . j av  a 2  s  .c  o m*/
 * @param clientId
 *            Identifier of the client requesting the token.
 * @param pkcs12Certificate
 *            PKCS12 certificate stream containing public and private key.
 *            Caller is responsible for handling the input stream.
 * @param password
 *            certificate password
 * @return KeyCredential instance
 * @throws KeyStoreException
 * @throws NoSuchProviderException
 * @throws NoSuchAlgorithmException
 * @throws CertificateException
 * @throws FileNotFoundException
 * @throws IOException
 * @throws UnrecoverableKeyException
 */
public static AsymmetricKeyCredential create(final String clientId, final InputStream pkcs12Certificate,
        final String password) throws KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException,
        CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException {
    final KeyStore keystore = KeyStore.getInstance("PKCS12", "SunJSSE");
    keystore.load(pkcs12Certificate, password.toCharArray());
    final Enumeration<String> aliases = keystore.aliases();
    final String alias = aliases.nextElement();
    final PrivateKey key = (PrivateKey) keystore.getKey(alias, password.toCharArray());
    final X509Certificate publicCertificate = (X509Certificate) keystore.getCertificate(alias);
    return create(clientId, key, publicCertificate);
}

From source file:com.church.tools.ChartTools.java

/**
 * Generate pie chart./*from  www  .  j a v a 2s  .c o m*/
 * 
 * @param title the title
 * @param values the values
 * @param captions the captions
 * @param width the width
 * @param height the height
 * @param color the color
 * 
 * @return the buffered image
 */
public static BufferedImage GeneratePieChart(String title, double[] values, String[] captions, int width,
        int height, Color color) {
    BufferedImage bufferedImage = null;
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    Hashtable<String, String> ht = new Hashtable<String, String>();
    for (int i = 0; i < values.length; i++)
        ht.put(captions[i], Double.toString(values[i]));

    Enumeration<String> enu = ht.keys();
    int i = 0;
    while (enu.hasMoreElements()) {
        String str = (String) enu.nextElement();
        pieDataset.setValue(str, new Double(Double.parseDouble((String) ht.get(str))));
        i++;
    }

    JFreeChart chart = ChartFactory.createPieChart(title, pieDataset, false, false, false);
    chart.setBackgroundPaint(color);
    bufferedImage = chart.createBufferedImage(width, height);
    return bufferedImage;
}

From source file:com.evanmclean.evlib.commons.dbcp.DbcpUtils.java

/**
 * Get the DBCP pooling driver.//  w  w w. j a  v a  2s.c  o  m
 * 
 * @return Return the DBCP pooling driver or null.
 */
public static PoolingDriver getPoolingDriver() {
    PoolingDriver pdriver = null;
    final Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        final Driver driver = drivers.nextElement();
        if (driver instanceof PoolingDriver) {
            if (pdriver == null)
                pdriver = (PoolingDriver) driver;
            else
                throw new IllegalStateException("More than one DBCP pooling driver.");
        }
    }
    return pdriver;
}

From source file:com.wmfsystem.eurekaserver.broadcast.Server.java

public static Set<InetAddress> getLocalAddress() throws SocketException {
    Set<InetAddress> address = new HashSet<>();
    Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> addresses = iface.getInetAddresses();

        while (addresses.hasMoreElements()) {
            InetAddress addr = addresses.nextElement();

            if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
                address.add(addr);//ww w  . j  a  v a 2 s  .  c  om
            }
        }
    }

    return address;
}

From source file:Main.java

/**
 * convert to List<T> from Enumeration<T>
 * /* ww  w. ja  v  a 2  s . c o m*/
 * @param enumeration
 * @return
 */
public static <T> List<T> convert(Enumeration<T> enumeration) {
    if (enumeration == null) {
        return Collections.emptyList();
    }
    ArrayList<T> result = new ArrayList<T>();
    while (enumeration.hasMoreElements()) {
        result.add(enumeration.nextElement());
    }
    return result;
}

From source file:com.apdplat.platform.spring.APDPlatContextLoaderListener.java

/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 *//*from  w w w .  j  a  v  a2 s .c  o  m*/
static void cleanupAttributes(ServletContext sc) {
    Enumeration attrNames = sc.getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String attrName = (String) attrNames.nextElement();
        if (attrName.startsWith("org.springframework.")) {
            Object attrValue = sc.getAttribute(attrName);
            if (attrValue instanceof DisposableBean) {
                try {
                    ((DisposableBean) attrValue).destroy();
                } catch (Throwable ex) {
                    logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'",
                            ex);
                }
            }
        }
    }
}

From source file:Main.java

public static int upZipFile(File zipFile, String folderPath) throws IOException {
    ZipFile zfile = new ZipFile(zipFile);
    Enumeration zList = zfile.entries();
    ZipEntry ze = null;/*from w w  w.j  av  a2 s  .co m*/
    byte[] buf = new byte[1024];
    while (zList.hasMoreElements()) {
        ze = (ZipEntry) zList.nextElement();
        if (ze.isDirectory()) {
            String dirstr = folderPath + ze.getName();
            dirstr = new String(dirstr.getBytes("8859_1"), "GB2312");
            File f = new File(dirstr);
            f.mkdirs();
            continue;
        }
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(getRealFileName(folderPath, ze.getName())));
        InputStream is = new BufferedInputStream(zfile.getInputStream(ze));
        int readLen = 0;
        while ((readLen = is.read(buf, 0, 1024)) != -1) {
            os.write(buf, 0, readLen);
        }
        is.close();
        os.close();
    }
    zfile.close();
    return 0;
}

From source file:MainClass.java

public static X509Certificate[] buildChain() throws Exception {
    KeyPair pair = generateRSAKeyPair();
    PKCS10CertificationRequest request = generateRequest(pair);

    KeyPair rootPair = generateRSAKeyPair();
    X509Certificate rootCert = generateV1Certificate(rootPair);

    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setIssuerDN(rootCert.getSubjectX500Principal());
    certGen.setNotBefore(new Date(System.currentTimeMillis()));
    certGen.setNotAfter(new Date(System.currentTimeMillis() + 10000));
    certGen.setSubjectDN(request.getCertificationRequestInfo().getSubject());
    certGen.setPublicKey(request.getPublicKey("BC"));
    certGen.setSignatureAlgorithm("SHA256WithRSAEncryption");

    certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
            new AuthorityKeyIdentifierStructure(rootCert));

    certGen.addExtension(X509Extensions.SubjectKeyIdentifier,

            false, new SubjectKeyIdentifierStructure(request.getPublicKey("BC")));

    certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false));

    certGen.addExtension(X509Extensions.KeyUsage, true,
            new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));

    certGen.addExtension(X509Extensions.ExtendedKeyUsage, true,
            new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));

    ASN1Set attributes = request.getCertificationRequestInfo().getAttributes();

    for (int i = 0; i != attributes.size(); i++) {
        Attribute attr = Attribute.getInstance(attributes.getObjectAt(i));

        if (attr.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
            X509Extensions extensions = X509Extensions.getInstance(attr.getAttrValues().getObjectAt(0));

            Enumeration e = extensions.oids();
            while (e.hasMoreElements()) {
                DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
                X509Extension ext = extensions.getExtension(oid);

                certGen.addExtension(oid, ext.isCritical(), ext.getValue().getOctets());
            }/*from  ww w  . ja  v a2  s  .c  o  m*/
        }
    }
    X509Certificate issuedCert = certGen.generateX509Certificate(rootPair.getPrivate());

    return new X509Certificate[] { issuedCert, rootCert };
}