Example usage for java.util Collections list

List of usage examples for java.util Collections list

Introduction

In this page you can find the example usage for java.util Collections list.

Prototype

public static <T> ArrayList<T> list(Enumeration<T> e) 

Source Link

Document

Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.

Usage

From source file:org.apereo.services.persondir.support.ldap.AttributeMapAttributesMapper.java

/**
 * Convert the Attribute's NamingEnumeration of values into a List
 *
 * @param values The enumeration of Attribute values
 * @return The List version of the values enumeration
 *//*  w w  w.ja  va  2  s .c  o  m*/
protected List<?> getAttributeValues(final NamingEnumeration<?> values) {
    return Collections.list(values);
}

From source file:org.eclipse.che.ide.ext.datasource.server.JdbcConnectionFactory.java

/**
 * builds a JDBC {@link Connection} for a datasource.
 *
 * @param configuration the datasource configuration
 * @return a connection/*from   w  ww .j a va  2 s  .co  m*/
 * @throws SQLException if the creation of the connection failed
 * @throws DatabaseDefinitionException if the configuration is incorrect
 */
public Connection getDatabaseConnection(final DatabaseConfigurationDTO configuration)
        throws SQLException, DatabaseDefinitionException {
    if (LOG.isInfoEnabled()) {
        Driver[] drivers = Collections.list(DriverManager.getDrivers()).toArray(new Driver[0]);
        LOG.info("Available jdbc drivers : {}", Arrays.toString(drivers));
    }

    Properties info = new Properties();
    info.setProperty("user", configuration.getUsername());

    final String password = configuration.getPassword();
    if (password != null && !password.isEmpty()) {
        try {
            info.setProperty("password", encryptTextService.decryptText(password));
        } catch (final Exception e1) {
            LOG.error("Couldn't decrypt the password, trying by setting the password without decryption", e1);
            info.setProperty("password", password);
        }
    } else {
        info.setProperty("password", "");
    }

    try {
        Map<String, String> preferences = getPreferences();

        CodenvySSLSocketFactoryKeyStoreSettings sslSettings = new CodenvySSLSocketFactoryKeyStoreSettings();
        if (configuration.getUseSSL()) {
            info.setProperty("useSSL", Boolean.toString(configuration.getUseSSL()));
            String sslKeyStore = preferences.get(KeyStoreObject.SSL_KEY_STORE_PREF_ID);
            sslSettings.setKeyStorePassword(SslKeyStoreService.getDefaultKeystorePassword());
            if (sslKeyStore != null) {
                sslSettings.setKeyStoreContent(Base64.decodeBase64(sslKeyStore));
            }
        }

        if (configuration.getVerifyServerCertificate()) {
            info.setProperty("verifyServerCertificate",
                    Boolean.toString(configuration.getVerifyServerCertificate()));
            String trustStore = preferences.get(KeyStoreObject.TRUST_STORE_PREF_ID);
            sslSettings.setTrustStorePassword(SslKeyStoreService.getDefaultTrustorePassword());
            if (trustStore != null) {
                sslSettings.setTrustStoreContent(Base64.decodeBase64(trustStore));
            }
        }

        CodenvySSLSocketFactory.keystore.set(sslSettings);

    } catch (Exception e) {
        LOG.error(
                "An error occured while getting keystore from Codenvy Preferences, JDBC connection will be performed without SSL",
                e);
    }
    final Connection connection = DriverManager.getConnection(getJdbcUrl(configuration), info);

    return connection;
}

From source file:com.fujitsu.dc.engine.rs.StatusResource.java

/**
 * Service./*from  ww  w  . j  a v  a  2s .  c  om*/
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        DcEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new DcEngineException("500 Internal Server Error (Unknown Error)",
                DcEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:io.personium.engine.rs.StatusResource.java

/**
 * Service./*from   w  w  w . j  av  a2  s  .  c om*/
 * @param path ??
 * @param req Request
 * @param res Response
 * @param is 
 * @return Response
 */
public final Response run(final String path, final HttpServletRequest req, final HttpServletResponse res,
        final InputStream is) {
    StringBuilder msg = new StringBuilder();
    msg.append(">>> Request Started ");
    msg.append(" method:");
    msg.append(req.getMethod());
    msg.append(" method:");
    msg.append(req.getRequestURL());
    msg.append(" url:");
    log.info(msg);

    // ? ????
    Enumeration<String> multiheaders = req.getHeaderNames();
    for (String headerName : Collections.list(multiheaders)) {
        Enumeration<String> headers = req.getHeaders(headerName);
        for (String header : Collections.list(headers)) {
            log.debug("RequestHeader['" + headerName + "'] = " + header);
        }
    }
    try {
        PersoniumEngineConfig.reload();
    } catch (Exception e) {
        log.warn(" unknown Exception(" + e.getMessage() + ")");
        return errorResponse(new PersoniumEngineException("500 Internal Server Error (Unknown Error)",
                PersoniumEngineException.STATUSCODE_SERVER_ERROR));
    }
    return Response.status(HttpStatus.SC_NO_CONTENT).build();
}

From source file:org.paxml.util.ReflectUtils.java

public static void traverseObject(Object obj, TraverseObjectCallback callback) {
    if (obj == null) {
        return;//from w  w w .ja  va2 s  .  c  o  m
    }
    Iterator it = null;
    if (obj instanceof Iterable) {
        it = ((Iterable) obj).iterator();
    } else if (obj instanceof Iterator) {
        it = (Iterator) obj;
    } else if (obj instanceof Enumeration) {
        it = Collections.list((Enumeration) obj).iterator();
    } else if (obj.getClass().isArray()) {
        it = new ArrayIterator(obj);
    } else if (obj instanceof String) {
        it = new ArrayIterator(StringUtils.split((String) obj));
    } else if (obj instanceof Map) {
        it = ((Map) obj).keySet().iterator();
    } else {
        it = Arrays.asList(obj).iterator();
    }
    while (it.hasNext()) {
        Object ele = it.next();
        if (!callback.onElement(ele)) {
            return;
        }
    }

}

From source file:com.buaa.cfs.net.DNS.java

/**
 * @param nif network interface to get addresses for
 *
 * @return set containing addresses for each subinterface of nif, see below for the rationale for using an ordered
 * set//from w  ww.jav  a2 s .  c  o  m
 */
private static LinkedHashSet<InetAddress> getSubinterfaceInetAddrs(NetworkInterface nif) {
    LinkedHashSet<InetAddress> addrs = new LinkedHashSet<InetAddress>();
    Enumeration<NetworkInterface> subNifs = nif.getSubInterfaces();
    while (subNifs.hasMoreElements()) {
        NetworkInterface subNif = subNifs.nextElement();
        addrs.addAll(Collections.list(subNif.getInetAddresses()));
    }
    return addrs;
}

From source file:org.springframework.boot.ops.trace.WebRequestTraceFilter.java

protected Map<String, Object> getTrace(HttpServletRequest request) {

    Map<String, Object> map = new LinkedHashMap<String, Object>();
    Enumeration<String> names = request.getHeaderNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();
        List<String> values = Collections.list(request.getHeaders(name));
        Object value = values;/*  w  w w.j a  v  a 2 s  .c o  m*/
        if (values.size() == 1) {
            value = values.get(0);
        } else if (values.isEmpty()) {
            value = "";
        }
        map.put(name, value);

    }
    Map<String, Object> trace = new LinkedHashMap<String, Object>();
    trace.put("method", request.getMethod());
    trace.put("path", request.getRequestURI());
    trace.put("headers", map);
    return trace;
}

From source file:org.openbaton.nfvo.system.SystemStartup.java

@Override
public void run(String... args) throws Exception {
    log.info("Initializing OpenBaton");

    log.debug(Arrays.asList(args).toString());

    propFileLocation = propFileLocation.replace("file:", "");
    log.debug("Property file: " + propFileLocation);

    InputStream is = new FileInputStream(propFileLocation);
    Properties properties = new Properties();
    properties.load(is);//from w w  w  . ja  v a  2 s. com

    log.debug("Config Values are: " + properties.values());

    Configuration c = new Configuration();

    c.setName("system");
    c.setConfigurationParameters(new HashSet<ConfigurationParameter>());

    /**
     * Adding properties from file
     */
    for (Entry<Object, Object> entry : properties.entrySet()) {
        ConfigurationParameter cp = new ConfigurationParameter();
        cp.setConfKey((String) entry.getKey());
        cp.setValue((String) entry.getValue());
        c.getConfigurationParameters().add(cp);
    }

    /**
     * Adding system properties
     */
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
        ConfigurationParameter cp = new ConfigurationParameter();
        log.trace("Display name: " + netint.getDisplayName());
        log.trace("Name: " + netint.getName());
        cp.setConfKey("ip-" + netint.getName().replaceAll("\\s", ""));
        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            if (inetAddress.getHostAddress().contains(".")) {
                log.trace("InetAddress: " + inetAddress.getHostAddress());
                cp.setValue(inetAddress.getHostAddress());
            }
        }
        log.trace("");
        c.getConfigurationParameters().add(cp);
    }

    configurationRepository.save(c);

    if (installPlugin) {
        startPlugins(pluginDir);
    }
}

From source file:foo.domaintest.email.EmailApiModule.java

@Provides
@RawEmailHeaders// w  w w  . j a va 2 s  . c  o m
@SuppressWarnings("unchecked")
String provideRawEmailHeaders(InternetHeaders headers) {
    return Joiner.on("\r\n").join(Collections.list(headers.getAllHeaderLines()));
}

From source file:javadepchecker.Main.java

/**
 * Scan jar for classes to be processed by ASM
 *
 * @param jar jar file to be processed/*from   ww  w.j a  va  2s.co  m*/
 * @throws IOException
 */
public void processJar(JarFile jar) throws IOException {
    Collections.list(jar.entries()).stream()
            .filter((JarEntry entry) -> (!entry.isDirectory() && entry.getName().endsWith("class")))
            .forEach((JarEntry entry) -> {
                InputStream is = null;
                try {
                    Main.this.mCurrent.add(entry.getName());
                    is = jar.getInputStream(entry);
                    new ClassReader(is).accept(Main.this, 0);
                } catch (IOException ex) {
                    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    try {
                        if (is != null)
                            is.close();
                    } catch (IOException ex) {
                        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            });
}