List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:de.tbuchloh.kiskis.gui.treeview.TreeView.java
/** * @return gets all the displayed tree nodes */// ww w . j a va 2 s. c o m protected Collection<MyTreeNode> getAllNodes() { final Queue<MyTreeNode> treeNodes = new LinkedList<MyTreeNode>(); treeNodes.add(getRoot()); final Collection<MyTreeNode> r = new LinkedList<MyTreeNode>(); r.add(getRoot()); while (!treeNodes.isEmpty()) { final MyTreeNode node = treeNodes.poll(); final List<MyTreeNode> children = Collections.list(node.children()); treeNodes.addAll(children); r.addAll(children); } return r; }
From source file:org.iavante.sling.gad.administration.impl.UploadOperations.java
/** * Sends the request to uploader.//from w w w . ja va2 s. c om * * @param request * @throws IOException */ public void sendSourceToUploader(HttpServletRequest request, String location, String coreurl, String rt) throws IOException, UploadException { init(); if (log.isInfoEnabled()) log.info("sendSourceToUploader, ini"); Enumeration en2 = request.getParameterNames(); while (en2.hasMoreElements()) { String cad = (String) en2.nextElement(); if (log.isInfoEnabled()) log.info("sendSourceToUploader, Param: " + cad); } String filename = request.getParameter("filename"); if (filename == null) { throw new UploadException("No <filename> param found in request"); } String content = request.getParameter("content"); if (content == null) { throw new UploadException("No <content> param found in request"); } List<String> names = Collections.list((Enumeration<String>) request.getParameterNames()); if (names.contains("data") && names.contains("filename") && names.contains("content")) { // Getting bytes from specific encoding. Otherwise doesn't work byte[] dataArray = request.getParameter("data").getBytes("ISO-8859-1"); // Setting POST Credentials creds = new UsernamePasswordCredentials(adminUser, adminPasswd); String postUrl = uploaderUrl + uploaderUploadApi; log.error("sendSourceToUploader, postUrl: " + postUrl); List<String> oksCodes = new ArrayList<String>(); oksCodes.add("" + HttpServletResponse.SC_OK); Part[] parts = null; if (coreurl == null) { parts = new Part[4]; parts[0] = new StringPart("content", location); parts[1] = new StringPart("filename", filename); parts[2] = new StringPart("rt", rt); parts[3] = new FilePart("data", new ByteArrayPartSource(filename, dataArray)); } else { parts = new Part[5]; parts[0] = new StringPart("coreurl", coreurl); parts[1] = new StringPart("content", location); parts[2] = new StringPart("filename", filename); parts[3] = new StringPart("rt", rt); parts[4] = new FilePart("data", new ByteArrayPartSource(filename, dataArray)); } Header[] headers = assertAuthenticatedPostMultipartStatus(creds, postUrl, oksCodes, parts, null); if (log.isInfoEnabled()) log.info("sendSourceToUploader, POST sent correctly to uploader"); } else { // send error log.error("sendSourceToUploader, POST failed"); throw new UploadException("sendSourceToUploader, data, filename or content params is missing"); } if (log.isInfoEnabled()) log.info("sendSourceToUploader, end"); }
From source file:eu.europa.esig.dss.cades.signature.CadesLevelBaselineLTATimestampExtractor.java
/** * The field certificatesHashIndex is a sequence of octet strings. Each one contains the hash value of one * instance of CertificateChoices within certificates field of the root SignedData. A hash value for * every instance of CertificateChoices, as present at the time when the corresponding archive time-stamp is * requested, shall be included in certificatesHashIndex. No other hash value shall be included in this field. * * @return//from w w w .j a v a 2s.co m * @throws eu.europa.esig.dss.DSSException */ @SuppressWarnings("unchecked") private ASN1Sequence getVerifiedCertificatesHashIndex(TimestampToken timestampToken) throws DSSException { final ASN1Sequence certHashes = getCertificatesHashIndex(timestampToken); final ArrayList<DEROctetString> certHashesList = Collections.list(certHashes.getObjects()); final List<CertificateToken> certificates = cadesSignature.getCertificatesWithinSignatureAndTimestamps(); for (final CertificateToken certificateToken : certificates) { final byte[] encodedCertificate = certificateToken.getEncoded(); final byte[] digest = DSSUtils.digest(hashIndexDigestAlgorithm, encodedCertificate); final DEROctetString derOctetStringDigest = new DEROctetString(digest); if (certHashesList.remove(derOctetStringDigest)) { // attribute present in signature and in timestamp LOG.debug("Cert {} present in timestamp", certificateToken.getAbbreviation()); } else { LOG.debug("Cert {} not present in timestamp", certificateToken.getAbbreviation()); } } if (!certHashesList.isEmpty()) { LOG.error("{} attribute hash in Cert Hashes have not been found in document attributes: {}", certHashesList.size(), certHashesList); // return a empty DERSequence to screw up the hash return new DERSequence(); } return certHashes; }
From source file:nl.eduvpn.app.service.VPNService.java
/** * Retrieves the IP4 and IPv6 addresses assigned by the VPN server to this client using a network interface lookup. * * @return The IPv4 and IPv6 addresses in this order as a pair. If not found, a null value is returned instead. */// w w w. j a va 2 s . c o m private Pair<String, String> _lookupVpnIpAddresses() { try { List<NetworkInterface> networkInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface networkInterface : networkInterfaces) { if (VPN_INTERFACE_NAME.equals(networkInterface.getName())) { List<InetAddress> addresses = Collections.list(networkInterface.getInetAddresses()); String ipV4 = null; String ipV6 = null; for (InetAddress address : addresses) { String ip = address.getHostAddress(); boolean isIPv4 = ip.indexOf(':') < 0; if (isIPv4) { ipV4 = ip; } else { int delimiter = ip.indexOf('%'); ipV6 = delimiter < 0 ? ip.toLowerCase() : ip.substring(0, delimiter).toLowerCase(); } } if (ipV4 != null || ipV6 != null) { return new Pair<>(ipV4, ipV6); } else { return null; } } } } catch (SocketException ex) { Log.w(TAG, "Unable to retrieve network interface info!", ex); } return null; }
From source file:com.triggertrap.ZeroConf.java
/** * Returns the first found IP4 address./*from ww w . j av a 2s.com*/ * * @return the first found IP4 address */ public static InetAddress getIPAddress(int wifi_ipaddr) { try { String ipString = String.format("%d.%d.%d.%d", (wifi_ipaddr & 0xff), (wifi_ipaddr >> 8 & 0xff), (wifi_ipaddr >> 16 & 0xff), (wifi_ipaddr >> 24 & 0xff)); List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress() && (ipString.equals(addr.getHostAddress()))) { //String sAddr = addr.getHostAddress().toUpperCase(); if (addr instanceof java.net.Inet4Address) { //Log.d("found IP address to listen: " , sAddr); return addr; } } } } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:cycronix.CTandroid.CTAserver.java
/** * Get IP address from first non-localhost interface * @param ipv4 true=return ipv4, false=return ipv6 * @return address or empty string/*from www . j a v a 2 s . c o m*/ */ public static String getIPAddress(boolean useIPv4) { try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); // org.apache.http.conn.util is no longer supported under Android API 23 // http://stackoverflow.com/questions/32141785/android-api-23-inetaddressutils-replacement // https://developer.android.com/sdk/api_diff/23/changes.html // boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); InetAddress tempInetAddress = InetAddress.getByName(sAddr); boolean isIPv4 = false; if (tempInetAddress instanceof Inet4Address) { isIPv4 = true; } if (useIPv4) { if (isIPv4) return sAddr; } else { if (!isIPv4) { int delim = sAddr.indexOf('%'); // drop ip6 port suffix return delim < 0 ? sAddr : sAddr.substring(0, delim); } } } } } } catch (Exception ex) { } // for now eat exceptions return "Unknown"; }
From source file:org.paxle.data.impl.Activator.java
@SuppressWarnings("unchecked") private void createAndRegisterProfileDB(URL hibernateConfigFile, BundleContext context, IDocumentFactory profileFactory) throws InvalidSyntaxException { // getting the mapping files to use Enumeration<URL> mappingFileEnum = context.getBundle().findEntries("/resources/hibernate/mapping/profile/", "*.hbm.xml", true); ArrayList<URL> mappings = Collections.list(mappingFileEnum); // create the profile-DB this.profileDB = new CommandProfileDB(hibernateConfigFile, mappings, profileFactory); // register it to the framework context.registerService(ICommandProfileManager.class.getName(), this.profileDB, null); }
From source file:com.l2jfree.L2Config.java
/** Flushes all pending log entries. */ // FIXME MMOLogger.flush() public static void flush() { // those are redirected to loggers, so flush them first System.out.flush();//from w ww . j a v a 2s.c om System.err.flush(); // then flush the loggers themselves final LogManager logManager = LogManager.getLogManager(); for (String loggerName : Collections.list(logManager.getLoggerNames())) { if (loggerName == null) continue; final Logger logger = logManager.getLogger(loggerName); if (logger == null) continue; for (Handler handler : logger.getHandlers()) if (handler != null) handler.flush(); } // and finally the real console streams L2Config.out.flush(); L2Config.err.flush(); }
From source file:de.jaetzold.networking.SimpleServiceDiscovery.java
/** * Comma separated List of IP adresses of available network interfaces * @param useIPv4/* www . j a v a 2s .c o m*/ * @return */ public static String getIPAddress(boolean useIPv4) { String addresses = ""; try { List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); if (useIPv4) { if (isIPv4) addresses += sAddr + ", "; } else { if (!isIPv4) { int delim = sAddr.indexOf('%'); // drop ip6 port suffix if (delim < 0) addresses += sAddr + ", "; else addresses += sAddr.substring(0, delim) + ", "; } } } } } } catch (Exception ex) { } // for now eat exceptions if (addresses == null || addresses.length() <= 3) return ""; return addresses.subSequence(0, addresses.length() - 2).toString(); }