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 <T> Iterator<T> iterator(Enumeration<T> enumeration) {
    return new Iterator<T>() {

        @Override//  w w w. ja v a2 s  .c  o m
        public boolean hasNext() {
            return enumeration.hasMoreElements();
        }

        @Override
        public T next() {
            return enumeration.nextElement();
        }
    };
}

From source file:Main.java

/**
 * Dictionary does not have an equals.//from  w ww .java  2  s .  co m
 * Please use  Map.equals().
 *
 * <p>Follows the equals contract of Java 2's Map.</p>
 * @param d1 the first directory.
 * @param d2 the second directory.
 * @return true if the directories are equal.
 * @since Ant 1.5
 * @deprecated since 1.6.x.
 */
public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) {
    if (d1 == d2) {
        return true;
    }

    if (d1 == null || d2 == null) {
        return false;
    }

    if (d1.size() != d2.size()) {
        return false;
    }

    Enumeration<?> e1 = d1.keys();
    while (e1.hasMoreElements()) {
        Object key = e1.nextElement();
        Object value1 = d1.get(key);
        Object value2 = d2.get(key);
        if (value2 == null || !value1.equals(value2)) {
            return false;
        }
    }

    // don't need the opposite check as the Dictionaries have the
    // same size, so we've also covered all keys of d2 already.

    return true;
}

From source file:Main.java

/**
 * Check whether the given Enumeration contains the given element.
 * @param enumeration the Enumeration to check
 * @param element the element to look for
 * @return {@code true} if found, {@code false} else
 *//*from   w  ww . j  a v  a 2s .  c  o m*/
public static boolean contains(Enumeration<?> enumeration, Object element) {
    if (enumeration != null) {
        while (enumeration.hasMoreElements()) {
            Object candidate = enumeration.nextElement();
            if (Objects.equals(candidate, element))
                return true;
        }
    }
    return false;
}

From source file:com.krawler.portal.util.SystemEnv.java

public static void setProperties(Properties props) {
    Properties envProps = getProperties();

    Enumeration<String> enu = (Enumeration<String>) envProps.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();

        props.setProperty("env." + key, (String) envProps.get(key));
    }// w ww  .j  a v a  2  s.c om
}

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());
            }/*  w  ww. j  a  v a  2 s .  co  m*/
        }
    }
    X509Certificate issuedCert = certGen.generateX509Certificate(rootPair.getPrivate());

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

From source file:com.qatickets.common.HttpUtils.java

public static Map<String, String> getHeadersAsMap(HttpServletRequest req) {
    final Map<String, String> headers = new HashMap<String, String>();
    final Enumeration enames = req.getHeaderNames();
    while (enames.hasMoreElements()) {
        final String name = (String) enames.nextElement();
        final String value = req.getHeader(name);
        headers.put(name, value);/*  ww  w  . j  a  v a 2  s .c o  m*/
    }
    return headers;
}

From source file:gov.nih.nci.protexpress.util.ConfigurationHelper.java

/**
 * @return the ldap context parameters.//from   ww w . j  av a 2  s .  c om
 */
public static Hashtable<String, String> getLdapContextParameters() {
    if (ldapContextParams == null) {
        ldapContextParams = new Hashtable<String, String>();

        ServletContext context = ServletActionContext.getServletContext();
        Enumeration<String> e = context.getInitParameterNames();
        while (e.hasMoreElements()) {
            String param = e.nextElement();
            if (param.startsWith("ldap")) {
                ldapContextParams.put(param, context.getInitParameter(param));
            }
        }
    }
    return ldapContextParams;
}

From source file:Main.java

public static <E> Iterator<E> asIterator(final Enumeration<E> e) {
    return new Iterator<E>() {
        @Override/*w  w w .j  av  a2 s .  c  o m*/
        public boolean hasNext() {
            return e.hasMoreElements();
        }

        @Override
        public E next() {
            return e.nextElement();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:Main.java

public static File UpdateZipFromPath(String sZipFile, String sPath) throws Exception {
    File tmpFile = File.createTempFile("z4zip-tmp-", ".zip");
    tmpFile.deleteOnExit();/*from   w ww .  j  a v a 2 s  . co  m*/
    ZipFile inZip = new ZipFile(sZipFile);
    ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(tmpFile.getPath()));

    Enumeration<? extends ZipEntry> entries = inZip.entries();
    while (entries.hasMoreElements()) {
        ZipEntry e = entries.nextElement();
        outZip.putNextEntry(e);
        if (!e.isDirectory()) {
            File f = new File(sPath + "/" + e.getName());
            if (f.exists()) {
                copy(new FileInputStream(f.getPath()), outZip);
            } else {
                copy(inZip.getInputStream(e), outZip);
            }
        }
        outZip.closeEntry();
    }
    inZip.close();
    outZip.close();
    return tmpFile;
}

From source file:info.magnolia.cms.filters.MultipartRequestFilter.java

/**
 * Adds all request paramaters as request attributes.
 * @param request HttpServletRequest//from   w  ww  .j a v  a 2s. c o m
 */
private static void parseParameters(HttpServletRequest request) throws IOException {
    MultipartForm form = new MultipartForm();
    String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8"); //$NON-NLS-1$
    MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding,
            null);
    Enumeration params = multi.getParameterNames();
    while (params.hasMoreElements()) {
        String name = (String) params.nextElement();
        String value = multi.getParameter(name);
        form.addParameter(name, value);
        String[] s = multi.getParameterValues(name);
        if (s != null) {
            form.addparameterValues(name, s);
        }
    }
    Enumeration files = multi.getFileNames();
    while (files.hasMoreElements()) {
        String name = (String) files.nextElement();
        form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name));
    }
    request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form);
}