List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.chromium.ChromeSystemNetwork.java
private void getNetworkInterfaces(final CordovaArgs args, final CallbackContext callbackContext) { cordova.getThreadPool().execute(new Runnable() { @Override// ww w . jav a 2 s. c om public void run() { try { JSONArray ret = new JSONArray(); ArrayList<NetworkInterface> interfaces = Collections .list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface iface : interfaces) { if (iface.isLoopback()) { continue; } for (InterfaceAddress interfaceAddress : iface.getInterfaceAddresses()) { InetAddress address = interfaceAddress.getAddress(); if (address == null) { continue; } JSONObject data = new JSONObject(); data.put("name", iface.getDisplayName()); // Strip address scope zones for IPv6 address. data.put("address", address.getHostAddress().replaceAll("%.*", "")); data.put("prefixLength", interfaceAddress.getNetworkPrefixLength()); ret.put(data); } } callbackContext.success(ret); } catch (Exception e) { Log.e(LOG_TAG, "Error occured while getting network interfaces", e); callbackContext.error("Could not get network interfaces"); } } }); }
From source file:org.jboss.qa.jenkins.test.executor.utils.unpack.UnZipper.java
@Override public void unpack(File archive, File destination) throws IOException { try (ZipFile zip = new ZipFile(archive)) { final Set<ZipArchiveEntry> entries = new HashSet<>(Collections.list(zip.getEntries())); if (ignoreRootFolders) { pathSegmentsToTrim = countRootFolders(entries); }/*w w w . j a va 2s . co m*/ for (ZipArchiveEntry entry : entries) { if (entry.isDirectory()) { continue; } final String zipPath = trimPathSegments(entry.getName(), pathSegmentsToTrim); final File file = new File(destination, zipPath); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); // Create parent folders if not exist } try (InputStream is = zip.getInputStream(entry); OutputStream fos = new FileOutputStream(file)) { IOUtils.copy(is, fos); // check for user-executable bit on entry and apply to file if ((entry.getUnixMode() & 0100) != 0) { file.setExecutable(true); } } file.setLastModified(entry.getTime()); } } }
From source file:Main.java
/** * Sorts <code>source</code> and adds the first n entries to * <code>dest</code>. If <code>source</code> contains less than n entries, * all of them are added to <code>dest</code>. * //from w w w .j av a 2 s . c om * If adding an entry to <code>dest</code> does not increase the * collection's size, for example if <code>dest</code> is a set and already * contained the inserted contact, an additional entry of * <code>source</code> will be added, if available. This guarantees that * <code>n</code> new, distinct entries are added to collection * <code>dest</code> as long as this can be fulfilled with the contents of * <code>source</code>, and as <code>dest</code> does recognise duplicate * entries. Consequently, this guarantee does not hold for simple lists. * * Both collections may not be <code>null</code>. * * @param <T> * the entry type of the collections. * @param source * the source collection. * @param dest * the destination collection. * @param order * the order in which <code>source</code> is to be sorted. * @param n * the number of new entries that are to be added to * <code>dest</code>. */ public static <T> void copyNSorted(final Collection<? extends T> source, final Collection<? super T> dest, final Comparator<? super T> order, final int n) { final List<? extends T> src = Collections.list(Collections.enumeration(source)); Collections.sort(src, order); final Iterator<? extends T> it = src.iterator(); final int maxEntries = dest.size() + n; while (it.hasNext() && dest.size() < maxEntries) { dest.add(it.next()); } }
From source file:se.inera.certificate.proxy.module.RequestInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) { for (String s : Collections.list(request.getHeaderNames())) { log.debug(s + ":" + request.getHeader(s)); }// w ww . ja v a 2 s .c o m return true; }
From source file:net.community.chest.gitcloud.facade.ServletUtils.java
public static final NamedExtendedPlaceholderResolver toPlaceholderResolver(final ServletContext context) { if (context == null) { return ExtendedPlaceholderResolverUtils.EMPTY_RESOLVER; } else {/*from w ww . j ava 2 s . c o m*/ return new NamedExtendedPlaceholderResolver() { @Override public String resolvePlaceholder(String placeholderName, String defaultValue) { String value = resolvePlaceholder(placeholderName); if (value == null) { return defaultValue; } else { return value; } } @Override public String resolvePlaceholder(String placeholderName) { return context.getInitParameter(placeholderName); } @Override public Collection<String> getPlaceholderNames() { return Collections.list(context.getInitParameterNames()); } }; } }
From source file:com.kevinshen.beyondupnp.util.Utils.java
/** * Returns MAC address of the given interface name. * * @param interfaceName eth0, wlan0 or NULL=use first interface * @return mac address or empty string// w ww . j a v a 2s . c om */ public static String getMACAddress(String interfaceName) { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { if (interfaceName != null) { if (!intf.getName().equalsIgnoreCase(interfaceName)) continue; } byte[] mac = intf.getHardwareAddress(); if (mac == null) return ""; StringBuilder buf = new StringBuilder(); for (int idx = 0; idx < mac.length; idx++) buf.append(String.format("%02X:", mac[idx])); if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1); return buf.toString(); } } catch (Exception ex) { } // for now eat exceptions return ""; }
From source file:psiprobe.jsp.ParamToggleTag.java
@Override public int doStartTag() throws JspException { boolean getSize = ServletRequestUtils.getBooleanParameter(pageContext.getRequest(), param, false); StringBuilder query = new StringBuilder(); query.append(param).append("=").append(!getSize); String encoding = pageContext.getResponse().getCharacterEncoding(); for (String name : Collections.list(pageContext.getRequest().getParameterNames())) { if (!param.equals(name)) { try { String value = ServletRequestUtils.getStringParameter(pageContext.getRequest(), name, ""); String encodedValue = URLEncoder.encode(value, encoding); query.append("&").append(name).append("=").append(encodedValue); } catch (UnsupportedEncodingException e) { throw new JspException(e); }/*from w w w .j ava2 s . c o m*/ } } try { pageContext.getOut().print(query); } catch (IOException e) { logger.debug("Exception printing query string to JspWriter", e); throw new JspException(e); } return EVAL_BODY_INCLUDE; }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoConnectionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!ConnectionManager.class.getName().equals(ref.getClassName())) { return null; }// w ww .java 2 s. c om if (NuxeoContainer.getConnectionManager() == null) { // initialize ConnectionManagerConfiguration config = new ConnectionManagerConfiguration(); for (RefAddr addr : Collections.list(ref.getAll())) { String name = addr.getType(); String value = (String) addr.getContent(); try { BeanUtils.setProperty(config, name, value); } catch (Exception e) { log.error(String.format("NuxeoConnectionManagerFactory cannot set %s = %s", name, value)); } } NuxeoContainer.initConnectionManager(config); } return NuxeoContainer.getConnectionManager(); }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoTransactionManagerFactory.java
@Override public Object getObjectInstance(Object obj, Name objName, Context nameCtx, Hashtable<?, ?> env) throws Exception { Reference ref = (Reference) obj; if (!TransactionManager.class.getName().equals(ref.getClassName())) { return null; }// ww w.j a v a 2 s.co m if (NuxeoContainer.getTransactionManager() == null) { // initialize TransactionManagerConfiguration config = new TransactionManagerConfiguration(); for (RefAddr addr : Collections.list(ref.getAll())) { String name = addr.getType(); String value = (String) addr.getContent(); try { BeanUtils.setProperty(config, name, value); } catch (Exception e) { log.error(String.format("NuxeoTransactionManagerFactory cannot set %s = %s", name, value)); } } NuxeoContainer.initTransactionManager(config); } return NuxeoContainer.getTransactionManager(); }
From source file:de.adorsys.oauth.authdispatcher.matcher.BasicAuthAuthenticatorMatcher.java
private static boolean isBasicAuthentication(HttpServletRequest httpServletRequest) { for (String name : Collections.list(httpServletRequest.getHeaderNames())) { if ("authorization".equalsIgnoreCase(name)) { return httpServletRequest.getHeader(name).substring(0, 5).equalsIgnoreCase("Basic"); }/*from w w w .ja v a2 s . c om*/ } return false; }