java.util.Enumeration#hasMoreElements ( )源码实例Demo

下面列出了java.util.Enumeration#hasMoreElements ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: securify   文件: SolidityResult.java
/**
 * Get the Securify version from the MANIFEST
 *
 * @return The version of Securify being executed
 */
private static String getVersion() {
    String className = Main.class.getCanonicalName();
    try {
        Enumeration<URL> resources = Main.class.getClassLoader()
                .getResources("META-INF/MANIFEST.MF");
        while (resources.hasMoreElements()) {
            Manifest manifest = new Manifest(resources.nextElement().openStream());
            Attributes at = manifest.getMainAttributes();
            Object main = at.getValue(MAIN_CLASS);
            if (main != null && at.getValue(MAIN_CLASS).equals(className) ) {
                return at.getValue(IMPLEMENTATION_VERSION);
            }
        }
    } catch (IOException e) {
        System.err.println("Error while setting Securify version");
        e.printStackTrace();
    }
    return "unknown_version";
}
 
源代码2 项目: quarkus   文件: SwaggerUiProcessor.java
private void extractSwaggerUi(AppArtifact artifact, Path resourceDir) throws IOException {
    final String versionedSwaggerUiWebjarPrefix = format("%s/%s/", SWAGGER_UI_WEBJAR_PREFIX, artifact.getVersion());
    for (Path p : artifact.getPaths()) {
        File artifactFile = p.toFile();
        try (JarFile jarFile = new JarFile(artifactFile)) {
            Enumeration<JarEntry> entries = jarFile.entries();
            while (entries.hasMoreElements()) {
                JarEntry entry = entries.nextElement();
                if (entry.getName().startsWith(versionedSwaggerUiWebjarPrefix) && !entry.isDirectory()) {
                    try (InputStream inputStream = jarFile.getInputStream(entry)) {
                        String filename = entry.getName().replace(versionedSwaggerUiWebjarPrefix, "");
                        Files.copy(inputStream, resourceDir.resolve(filename));
                    }
                }
            }
        }
    }
}
 
/**
 * Build a list of subscription by a particular module
 *
 * @param moduleName       Name of the module
 * @param moduleProperties Set of properties which
 * @return A list of subscriptions by the module
 */
private List<Subscription> buildSubscriptionList(String moduleName, Properties moduleProperties) {
    // Get subscribed events
    Properties subscriptions = NotificationManagementUtils.getSubProperties(moduleName + "." +
            NotificationMgtConstants.Configs.SUBSCRIPTION, moduleProperties);

    List<Subscription> subscriptionList = new ArrayList<Subscription>();
    Enumeration propertyNames = subscriptions.propertyNames();
    // Iterate through events and build event objects
    while (propertyNames.hasMoreElements()) {
        String key = (String) propertyNames.nextElement();
        String subscriptionName = (String) subscriptions.remove(key);
        // Read all the event properties starting from the event prefix
        Properties subscriptionProperties = NotificationManagementUtils.getPropertiesWithPrefix
                (moduleName + "." + NotificationMgtConstants.Configs.SUBSCRIPTION + "." + subscriptionName,
                        moduleProperties);
        Subscription subscription = new Subscription(subscriptionName, subscriptionProperties);
        subscriptionList.add(subscription);
    }
    return subscriptionList;
}
 
源代码4 项目: djvu-html5   文件: DjVuText.java
/**
 * Searches a file for TXTz and TXTa chunks and decodes each of them.
 *
 * @param iff enumeration of CachedInputStream's to read.
 *
 * @return the initialized DjVuText object
 *
 * @throws IOException if an IO error occures.
 */
public DjVuText init(final Enumeration<CachedInputStream> iff)
  throws IOException
{
  if(iff != null)
  {
    while(iff.hasMoreElements())
    {
      CachedInputStream chunk=iff.nextElement();
      final String xchkid = chunk.getName();
      if(xchkid.startsWith("FORM:"))
      {
        init(chunk.getIFFChunks());
      }
      else if("TXTa".equals(xchkid)||"TXTz".equals(xchkid))
      {
        decode(chunk);
      }
    }
  }
  return this;
}
 
源代码5 项目: jdk8u-jdk   文件: MultiUIDefaults.java
@Override
public synchronized String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append("{");
    Enumeration keys = keys();
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        buf.append(key + "=" + get(key) + ", ");
    }
    int length = buf.length();
    if (length > 1) {
        buf.delete(length-2, length);
    }
    buf.append("}");
    return buf.toString();
}
 
源代码6 项目: hadoop-ozone   文件: OzoneConfiguration.java
private void loadDefaults() {
  try {
    //there could be multiple ozone-default-generated.xml files on the
    // classpath, which are generated by the annotation processor.
    // Here we add all of them to the list of the available configuration.
    Enumeration<URL> generatedDefaults =
        OzoneConfiguration.class.getClassLoader().getResources(
            "ozone-default-generated.xml");
    while (generatedDefaults.hasMoreElements()) {
      addResource(generatedDefaults.nextElement());
    }
  } catch (IOException e) {
    e.printStackTrace();
  }
  // Adding core-site here because properties from core-site are
  // distributed to executors by spark driver. Ozone properties which are
  // added to core-site, will be overriden by properties from adding Resource
  // ozone-default.xml. So, adding core-site again will help to resolve
  // this override issue.
  addResource("core-site.xml");
  addResource("ozone-site.xml");
}
 
源代码7 项目: jmg   文件: Mod.java
/**
    * Lengthen each note in the CPhrase.
    *
    * <P> See {@link #elongate(Phrase, double)} for further details.
    *
    * <P> If <CODE>cphrase</CODE> is null or <CODE>scaleFactor</CODE> is less
    * than or equal to zero then this method does nothing.
    *
    * @param cphrase       CPhrase to be lengthened
    * @param scaleFactor   double describing the scale factor
 */
   public static void elongate(CPhrase cphrase, final double scaleFactor) {
       if (cphrase == null || scaleFactor <= 0.0) {
           return;
       }
       Enumeration enum1 = cphrase.getPhraseList().elements();
	while(enum1.hasMoreElements()){
		Phrase phr = ((Phrase) enum1.nextElement());
           elongate(phr, scaleFactor);
		phr.setStartTime(phr.getStartTime() * scaleFactor);
	}
}
 
源代码8 项目: Bytecoder   文件: MockAttributeSet.java
public void addAttributes(AttributeSet attr)
{
    Enumeration<?> as = attr.getAttributeNames();
    while(as.hasMoreElements()) {
        Object el = as.nextElement();
        backing.put(el, attr.getAttribute(el));
    }
}
 
源代码9 项目: netbeans   文件: NewPluginPanel.java
public List<String> getGoals () {
    List<String> goals = new ArrayList<String>();
    Enumeration e  = listModel.elements();
    GoalEntry ge;
    while (e.hasMoreElements()) {
        ge = (GoalEntry) e.nextElement();
        if (ge.isSelected) {
            goals.add(ge.name);
        }
    }
    return goals;
}
 
源代码10 项目: BiglyBT   文件: V2TBSCertListGenerator.java
public TBSCertList generateTBSCertList()
{
    if ((signature == null) || (issuer == null) || (thisUpdate == null))
    {
        throw new IllegalStateException("Not all mandatory fields set in V2 TBSCertList generator.");
    }

    ASN1EncodableVector  v = new ASN1EncodableVector();

    v.add(version);
    v.add(signature);
    v.add(issuer);

    v.add(thisUpdate);
    if (nextUpdate != null)
    {
        v.add(nextUpdate);
    }

    // Add CRLEntries if they exist
    if (crlentries != null)
    {
        ASN1EncodableVector certs = new ASN1EncodableVector();
        Enumeration it = crlentries.elements();
        while(it.hasMoreElements())
        {
            certs.add((ASN1Sequence)it.nextElement());
        }
        v.add(new DERSequence(certs));
    }

    if (extensions != null)
    {
        v.add(new DERTaggedObject(0, extensions));
    }

    return new TBSCertList(new DERSequence(v));
}
 
源代码11 项目: obfuscator   文件: ObfuscatorTest.java
@Test
public void testObfuscatedJar() throws IOException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
    int rightValue = 704643072;
    JarFile jarFile = new JarFile(obfuscatedFile);
    Enumeration<JarEntry> e = jarFile.entries();

    URL[] urls = {new URL("jar:file:" + obfuscatedFile.getAbsolutePath() + "!/")};
    URLClassLoader cl = URLClassLoader.newInstance(urls);
    Class<?> c = null;

    while (e.hasMoreElements()) {
        JarEntry je = e.nextElement();
        if (je.isDirectory() || !je.getName().endsWith(".class")) {
            continue;
        }
        // -6 because of .class
        String className = je.getName().substring(0, je.getName().length() - 6);
        className = className.replace('/', '.');
        if (className.equals("JFT")) {
            c = cl.loadClass(className);
        }
    }

    if (c == null) {
        fail("JFT.class wasn't found");
    }

    assertEquals(((int) c.getMethod("test").invoke(null)), rightValue);
}
 
源代码12 项目: cs-actions   文件: SendMailService.java
private void addEncryptionSettings() throws Exception {
    URL keystoreUrl = new URL(input.getEncryptionKeystore());
    try (InputStream publicKeystoreInputStream = keystoreUrl.openStream()) {
        char[] smimePw = input.getEncryptionKeystorePassword().toCharArray();
        gen = new SMIMEEnvelopedGenerator();
        Security.addProvider(new BouncyCastleProvider());
        KeyStore ks = KeyStore.getInstance(SecurityConstants.PKCS_KEYSTORE_TYPE, SecurityConstants.BOUNCY_CASTLE_PROVIDER);
        ks.load(publicKeystoreInputStream, smimePw);

        if (StringUtils.EMPTY.equals(input.getEncryptionKeyAlias())) {
            Enumeration aliases = ks.aliases();
            while (aliases.hasMoreElements()) {
                String alias = (String) aliases.nextElement();

                if (ks.isKeyEntry(alias)) {
                    input.setEncryptionKeyAlias(alias);
                }
            }
        }

        if (StringUtils.EMPTY.equals(input.getEncryptionKeyAlias())) {
            throw new Exception(ExceptionMsgs.PUBLIC_KEY_ERROR_MESSAGE);
        }

        Certificate[] chain = ks.getCertificateChain(input.getEncryptionKeyAlias());

        if (chain == null) {
            throw new Exception("The key with alias \"" + input.getEncryptionKeyAlias() + "\" can't be found in given keystore.");
        }

        //
        // create the generator for creating an smime/encrypted message
        //
        gen.addKeyTransRecipient((X509Certificate) chain[0]);
    }
}
 
源代码13 项目: cxf   文件: OASISCatalogManager.java
public final void loadCatalogs(ClassLoader classLoader, String name) throws IOException {
    if (classLoader == null) {
        return;
    }

    Enumeration<URL> catalogs = classLoader.getResources(name);
    while (catalogs.hasMoreElements()) {
        final URL catalogURL = catalogs.nextElement();
        if (catalog == null) {
            LOG.log(Level.WARNING, "Catalog found at {0} but no org.apache.xml.resolver.CatalogManager was found."
                    + "  Check the classpatch for an xmlresolver jar.", catalogURL.toString());
        } else if (!loadedCatalogs.contains(catalogURL.toString())) {
            final SecurityManager sm = System.getSecurityManager();
            if (sm == null) {
                ((Catalog)catalog).parseCatalog(catalogURL);
            } else {
                try {
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Void>() {
                        @Override
                        public Void run() throws Exception {
                            ((Catalog)catalog).parseCatalog(catalogURL);
                            return null;
                        }
                    });
                } catch (PrivilegedActionException e) {
                    throw (IOException) e.getException();
                }
            }
            loadedCatalogs.add(catalogURL.toString());
        }
    }
}
 
源代码14 项目: spliceengine   文件: TestConfiguration.java
/**
 * Create a copy of this configuration with some additional connection
 * attributes.
 *
 * @param attrs the extra connection attributes
 * @return a copy of the configuration with extra attributes
 */
TestConfiguration addConnectionAttributes(Properties attrs) {
    TestConfiguration copy = new TestConfiguration(this);
    Enumeration e = attrs.propertyNames();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        String val = attrs.getProperty(key);
        copy.connectionAttributes.setProperty(key, val);
    }
    copy.initConnector(connector);
    return copy;
}
 
源代码15 项目: tomee   文件: AlternativeDriver.java
private boolean isRegistered() {
    final Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {

        final Driver driver = drivers.nextElement();

        if (driver == this) {
            return true;
        }
    }

    return false;
}
 
源代码16 项目: openjdk-8-source   文件: BasicPermission.java
/**
 * readObject is called to restore the state of the
 * BasicPermissionCollection from a stream.
 */
private void readObject(java.io.ObjectInputStream in)
     throws IOException, ClassNotFoundException
{
    // Don't call defaultReadObject()

    // Read in serialized fields
    ObjectInputStream.GetField gfields = in.readFields();

    // Get permissions
    // writeObject writes a Hashtable<String, Permission> for the
    // permissions key, so this cast is safe, unless the data is corrupt.
    @SuppressWarnings("unchecked")
    Hashtable<String, Permission> permissions =
            (Hashtable<String, Permission>)gfields.get("permissions", null);
    perms = new HashMap<String, Permission>(permissions.size()*2);
    perms.putAll(permissions);

    // Get all_allowed
    all_allowed = gfields.get("all_allowed", false);

    // Get permClass
    permClass = (Class<?>) gfields.get("permClass", null);

    if (permClass == null) {
        // set permClass
        Enumeration<Permission> e = permissions.elements();
        if (e.hasMoreElements()) {
            Permission p = e.nextElement();
            permClass = p.getClass();
        }
    }
}
 
源代码17 项目: MRouter   文件: RouterInitGenerator.java
public static void updateInitClassBytecode(GlobalInfo globalInfo) throws IOException {
    for (File file : globalInfo.getRouterInitTransformFiles()) {
        if (file.getName().endsWith(".jar")) {
            JarFile jarFile = new JarFile(file);
            Enumeration enumeration = jarFile.entries();

            // create tmp jar file
            File tmpJarFile = new File(file.getParent(), file.getName() + ".tmp");

            if (tmpJarFile.exists()) {
                tmpJarFile.delete();
            }

            JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(tmpJarFile));

            while (enumeration.hasMoreElements()) {
                JarEntry jarEntry = (JarEntry) enumeration.nextElement();
                // eg. com/google/common/collect/AbstractTable.class
                String entryName = jarEntry.getName();
                ZipEntry zipEntry = new ZipEntry(entryName);
                InputStream inputStream = jarFile.getInputStream(jarEntry);
                jarOutputStream.putNextEntry(zipEntry);
                if (Utils.isRouterInitClass(globalInfo, entryName.replace(".class", ""))) {
                    byte[] bytes = generateClassBytes(globalInfo, inputStream);
                    jarOutputStream.write(bytes);
                } else {
                    jarOutputStream.write(IOUtils.toByteArray(inputStream));
                }
                // inputStream.close(); close by ClassReader
                jarOutputStream.closeEntry();
            }
            jarOutputStream.close();
            jarFile.close();

            if (file.exists()) {
                file.delete();
            }
            tmpJarFile.renameTo(file);
        } else {
            byte[] classBytes = generateClassBytes(globalInfo, new FileInputStream(file));
            FileUtils.writeByteArrayToFile(file, classBytes, false);
        }
    }
}
 
源代码18 项目: mycore   文件: MCREchoResource.java
@GET
@Produces(MediaType.APPLICATION_JSON)
@MCRRestrictedAccess(MCRRequireLogin.class)
public String doEcho() {
    Gson gson = new Gson();
    JsonObject jRequest = new JsonObject();
    jRequest.addProperty("secure", request.isSecure());
    jRequest.addProperty("authType", request.getAuthType());
    jRequest.addProperty("context", request.getContextPath());
    jRequest.addProperty("localAddr", request.getLocalAddr());
    jRequest.addProperty("localName", request.getLocalName());
    jRequest.addProperty("method", request.getMethod());
    jRequest.addProperty("pathInfo", request.getPathInfo());
    jRequest.addProperty("protocol", request.getProtocol());
    jRequest.addProperty("queryString", request.getQueryString());
    jRequest.addProperty("remoteAddr", request.getRemoteAddr());
    jRequest.addProperty("remoteHost", request.getRemoteHost());
    jRequest.addProperty("remoteUser", request.getRemoteUser());
    jRequest.addProperty("remotePort", request.getRemotePort());
    jRequest.addProperty("requestURI", request.getRequestURI());
    jRequest.addProperty("scheme", request.getScheme());
    jRequest.addProperty("serverName", request.getServerName());
    jRequest.addProperty("servletPath", request.getServletPath());
    jRequest.addProperty("serverPort", request.getServerPort());

    HttpSession session = request.getSession(false);
    List<String> attributes = Collections.list(session.getAttributeNames());
    JsonObject sessionJSON = new JsonObject();
    JsonObject attributesJSON = new JsonObject();
    attributes.forEach(attr -> attributesJSON.addProperty(attr, session.getAttribute(attr).toString()));
    sessionJSON.add("attributes", attributesJSON);
    sessionJSON.addProperty("id", session.getId());
    sessionJSON.addProperty("creationTime", session.getCreationTime());
    sessionJSON.addProperty("lastAccessedTime", session.getLastAccessedTime());
    sessionJSON.addProperty("maxInactiveInterval", session.getMaxInactiveInterval());
    sessionJSON.addProperty("isNew", session.isNew());
    jRequest.add("session", sessionJSON);

    jRequest.addProperty("localPort", request.getLocalPort());
    JsonArray jLocales = new JsonArray();
    Enumeration<Locale> locales = request.getLocales();
    while (locales.hasMoreElements()) {
        jLocales.add(gson.toJsonTree(locales.nextElement().toString()));
    }
    jRequest.add("locales", jLocales);
    JsonObject header = new JsonObject();
    jRequest.add("header", header);
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = headerNames.nextElement();
        String headerValue = request.getHeader(headerName);
        header.addProperty(headerName, headerValue);
    }
    JsonObject parameter = new JsonObject();
    jRequest.add("parameter", parameter);
    for (Map.Entry<String, String[]> param : request.getParameterMap().entrySet()) {
        if (param.getValue().length == 1) {
            parameter.add(param.getKey(), gson.toJsonTree(param.getValue()[0]));
        } else {
            parameter.add(param.getKey(), gson.toJsonTree(param.getValue()));
        }
    }
    return jRequest.toString();
}
 
源代码19 项目: nifi   文件: JmsFactory.java
public static Map<String, String> createAttributeMap(final Message message) throws JMSException {
    final Map<String, String> attributes = new HashMap<>();

    final Enumeration<?> enumeration = message.getPropertyNames();
    while (enumeration.hasMoreElements()) {
        final String propName = (String) enumeration.nextElement();

        final Object value = message.getObjectProperty(propName);

        if (value == null) {
            attributes.put(ATTRIBUTE_PREFIX + propName, "");
            attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, "Unknown");
            continue;
        }

        final String valueString = value.toString();
        attributes.put(ATTRIBUTE_PREFIX + propName, valueString);

        final String propType;
        if (value instanceof String) {
            propType = PROP_TYPE_STRING;
        } else if (value instanceof Double) {
            propType = PROP_TYPE_DOUBLE;
        } else if (value instanceof Float) {
            propType = PROP_TYPE_FLOAT;
        } else if (value instanceof Long) {
            propType = PROP_TYPE_LONG;
        } else if (value instanceof Integer) {
            propType = PROP_TYPE_INTEGER;
        } else if (value instanceof Short) {
            propType = PROP_TYPE_SHORT;
        } else if (value instanceof Byte) {
            propType = PROP_TYPE_BYTE;
        } else if (value instanceof Boolean) {
            propType = PROP_TYPE_BOOLEAN;
        } else {
            propType = PROP_TYPE_OBJECT;
        }

        attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, propType);
    }

    if (message.getJMSCorrelationID() != null) {
        attributes.put(ATTRIBUTE_PREFIX + JMS_CORRELATION_ID, message.getJMSCorrelationID());
    }
    if (message.getJMSDestination() != null) {
        String destinationName;
        if (message.getJMSDestination() instanceof Queue) {
            destinationName = ((Queue) message.getJMSDestination()).getQueueName();
        } else {
            destinationName = ((Topic) message.getJMSDestination()).getTopicName();
        }
        attributes.put(ATTRIBUTE_PREFIX + JMS_DESTINATION, destinationName);
    }
    if (message.getJMSMessageID() != null) {
        attributes.put(ATTRIBUTE_PREFIX + JMS_MESSAGE_ID, message.getJMSMessageID());
    }
    if (message.getJMSReplyTo() != null) {
        attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());
    }
    if (message.getJMSType() != null) {
        attributes.put(ATTRIBUTE_PREFIX + JMS_TYPE, message.getJMSType());
    }

    attributes.put(ATTRIBUTE_PREFIX + JMS_DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
    attributes.put(ATTRIBUTE_PREFIX + JMS_EXPIRATION, String.valueOf(message.getJMSExpiration()));
    attributes.put(ATTRIBUTE_PREFIX + JMS_PRIORITY, String.valueOf(message.getJMSPriority()));
    attributes.put(ATTRIBUTE_PREFIX + JMS_REDELIVERED, String.valueOf(message.getJMSRedelivered()));
    attributes.put(ATTRIBUTE_PREFIX + JMS_TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
    return attributes;
}
 
public void registerHooks(Archive archive, ClassLoader classLoader) throws PackageException {
    try {
        Archive.Entry root = archive.getRoot();
        root = root.getChild(Constants.META_INF);
        if (root == null) {
            log.warn("Archive {} does not have a {} directory.", archive, Constants.META_INF);
            return;
        }
        root = root.getChild(Constants.VAULT_DIR);
        if (root == null) {
            log.warn("Archive {} does not have a {} directory.", archive, Constants.VAULT_DIR);
            return;
        }
        root = root.getChild(Constants.HOOKS_DIR);
        if (root == null) {
            log.debug("Archive {} does not have a {} directory.", archive, Constants.HOOKS_DIR);
        } else {
            for (Archive.Entry entry : root.getChildren()) {
                // only respect .jar files
                if (entry.getName().endsWith(".jar")) {
                    registerHook(archive.getInputSource(entry), classLoader);
                }
            }
        }
        
        // also look for external hooks in properties
        // currently only the format: "installhook.{name}.class" is supported
        Properties props = archive.getMetaInf().getProperties();
        if (props != null) {
            Enumeration<?> names = props.propertyNames();
            while (names.hasMoreElements()) {
                String name = names.nextElement().toString();
                if (name.startsWith(VaultPackage.PREFIX_INSTALL_HOOK)) {
                    String[] segs = Text.explode(name.substring(VaultPackage.PREFIX_INSTALL_HOOK.length()), '.');
                    if (segs.length == 0 || segs.length > 2 || !"class".equals(segs[1])) {
                        throw new PackageException("Invalid installhook property: " + name);
                    }
                    Hook hook = new Hook(segs[0], props.getProperty(name), classLoader);
                    initHook(hook);
                }
            }
        }
    } catch (IOException e) {
        throw new PackageException("I/O Error while registering hooks", e);
    }
}