List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.jivesoftware.openfire.clearspace.ClearspaceManager.java
private List<String> getServerInterfaces() { List<String> bindInterfaces = new ArrayList<String>(); String interfaceName = JiveGlobals.getXMLProperty("network.interface"); String bindInterface = null;/* www. j a v a 2 s . c om*/ if (interfaceName != null) { if (interfaceName.trim().length() > 0) { bindInterface = interfaceName; } } int adminPort = JiveGlobals.getXMLProperty("adminConsole.port", 9090); int adminSecurePort = JiveGlobals.getXMLProperty("adminConsole.securePort", 9091); if (bindInterface == null) { try { Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface netInterface : Collections.list(nets)) { Enumeration<InetAddress> addresses = netInterface.getInetAddresses(); for (InetAddress address : Collections.list(addresses)) { if ("127.0.0.1".equals(address.getHostAddress())) { continue; } if (address.getHostAddress().startsWith("0.")) { continue; } Socket socket = new Socket(); InetSocketAddress remoteAddress = new InetSocketAddress(address, adminPort > 0 ? adminPort : adminSecurePort); try { socket.connect(remoteAddress); bindInterfaces.add(address.getHostAddress()); break; } catch (IOException e) { // Ignore this address. Let's hope there is more addresses to validate } } } } catch (SocketException e) { // We failed to discover a valid IP address where the admin console is running return null; } } else { bindInterfaces.add(bindInterface); } return bindInterfaces; }
From source file:de.mangelow.throughput.NotificationService.java
private String getIPAddress() { try {/*from w w w . j av a 2 s.c om*/ String ipv4; List<NetworkInterface> nilist = Collections.list(NetworkInterface.getNetworkInterfaces()); if (nilist.size() > 0) { for (NetworkInterface ni : nilist) { List<InetAddress> ialist = Collections.list(ni.getInetAddresses()); if (ialist.size() > 0) { for (InetAddress address : ialist) { if (!address.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ipv4 = address.getHostAddress())) { return ipv4; } } } } } } catch (SocketException ex) { if (D) ex.printStackTrace(); } return ""; }
From source file:ca.psiphon.PsiphonTunnel.java
private static PrivateAddress selectPrivateAddress() throws Exception { // Select one of 10.0.0.1, 172.16.0.1, or 192.168.0.1 depending on // which private address range isn't in use. Map<String, PrivateAddress> candidates = new HashMap<String, PrivateAddress>(); candidates.put("10", new PrivateAddress("10.0.0.1", "10.0.0.0", 8, "10.0.0.2")); candidates.put("172", new PrivateAddress("172.16.0.1", "172.16.0.0", 12, "172.16.0.2")); candidates.put("192", new PrivateAddress("192.168.0.1", "192.168.0.0", 16, "192.168.0.2")); candidates.put("169", new PrivateAddress("169.254.1.1", "169.254.1.0", 24, "169.254.1.2")); List<NetworkInterface> netInterfaces; try {// w w w . ja va 2 s .c o m netInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); } catch (SocketException e) { throw new Exception("selectPrivateAddress failed", e); } for (NetworkInterface netInterface : netInterfaces) { for (InetAddress inetAddress : Collections.list(netInterface.getInetAddresses())) { String ipAddress = inetAddress.getHostAddress(); if (InetAddressUtils.isIPv4Address(ipAddress)) { if (ipAddress.startsWith("10.")) { candidates.remove("10"); } else if (ipAddress.length() >= 6 && ipAddress.substring(0, 6).compareTo("172.16") >= 0 && ipAddress.substring(0, 6).compareTo("172.31") <= 0) { candidates.remove("172"); } else if (ipAddress.startsWith("192.168")) { candidates.remove("192"); } } } } if (candidates.size() > 0) { return candidates.values().iterator().next(); } throw new Exception("no private address available"); }
From source file:org.apache.hadoop.filecache.DistributedCache.java
/** * Get the file entries in classpath as an array of Path * //from w ww.j a va 2 s . c o m * @param conf * Configuration that contains the classpath setting */ public static Path[] getFileClassPaths(Configuration conf) { String classpath = conf.get("mapred.job.classpath.files"); if (classpath == null) return null; ArrayList list = Collections.list(new StringTokenizer(classpath, System.getProperty("path.separator"))); Path[] paths = new Path[list.size()]; for (int i = 0; i < list.size(); i++) { paths[i] = new Path((String) list.get(i)); } return paths; }
From source file:org.dbflute.saflute.web.servlet.filter.RequestLoggingFilter.java
protected SortedSet<?> toSortedSet(final Enumeration<?> enu) { final SortedSet<Object> set = new TreeSet<Object>(); set.addAll(Collections.list(enu)); return set;/*w w w. j a v a2 s . co m*/ }
From source file:com.fiorano.openesb.application.application.ApplicationReference.java
/** * Converts to new DMI/* www . j ava 2 s .c o m*/ * @param that old DMI */ public void convert(ApplicationHeader that) { guid = that.getApplicationGUID(); version = Float.parseFloat(that.getVersionNumber()); displayName = that.getApplicationName(); categories = Arrays.asList(that.getCategoryIn().split(",")); creationDate = that.getCreationDateAsDate(); authors = (String[]) Collections.list(that.getAuthors()).toArray(); shortDescription = that.getShortDescription(); longDescription = that.getLongDescription(); label = that.getProfile(); componentCached = !that.isServiceNoCache(); }
From source file:org.apache.hadoop.filecache.DistributedCache.java
/** * Get the archive entries in classpath as an array of Path * //from ww w. j av a 2 s . c o m * @param conf * Configuration that contains the classpath setting */ public static Path[] getArchiveClassPaths(Configuration conf) { String classpath = conf.get("mapred.job.classpath.archives"); if (classpath == null) return null; ArrayList list = Collections.list(new StringTokenizer(classpath, System.getProperty("path.separator"))); Path[] paths = new Path[list.size()]; for (int i = 0; i < list.size(); i++) { paths[i] = new Path((String) list.get(i)); } return paths; }
From source file:com.ichi2.libanki.Media.java
/** * Extract zip data; return the number of files extracted. Unlike the python version, this method consumes a * ZipFile stored on disk instead of a String buffer. Holding the entire downloaded data in memory is not feasible * since some devices can have very limited heap space. * * This method closes the file before it returns. *//*from w w w .ja v a2 s .c om*/ public int addFilesFromZip(ZipFile z) throws IOException { try { List<Object[]> media = new ArrayList<Object[]>(); // get meta info first JSONObject meta = new JSONObject(Utils.convertStreamToString(z.getInputStream(z.getEntry("_meta")))); // then loop through all files int cnt = 0; for (ZipEntry i : Collections.list(z.entries())) { if (i.getName().equals("_meta")) { // ignore previously-retrieved meta continue; } else { String name = meta.getString(i.getName()); // normalize name for platform name = HtmlUtil.nfcNormalized(name); // save file String destPath = dir().concat(File.separator).concat(name); Utils.writeToFile(z.getInputStream(i), destPath); String csum = Utils.fileChecksum(destPath); // update db media.add(new Object[] { name, csum, _mtime(destPath), 0 }); cnt += 1; } } if (media.size() > 0) { mDb.executeMany("insert or replace into media values (?,?,?,?)", media); } return cnt; } catch (JSONException e) { throw new RuntimeException(e); } finally { z.close(); } }
From source file:org.cesecore.keys.token.BaseCryptoToken.java
@Override public List<String> getAliases() throws KeyStoreException, CryptoTokenOfflineException { return Collections.list(getKeyStore().aliases()); }
From source file:org.xwoot.jxta.mock.MockJxtaPeer.java
/** * Authenticate membership in a peer group using {@link PSEMembershipService}'s \"StringAuthentication\" method. * </p>//w w w .j a v a2 s .co m * If both passwords are not provided, the authentication is made using {@link NoneMembershipService} and no authentication data is provided. * * @param keystorePassword the password of the local keystore. * @param identityPassword the group's password. * * @return true if successful, false if the provided passwords were not correct or joining failed. * @throws PeerGroupException if problems occurred joining the group. * @throws ProtocolNotSupportedException if problems occur authenticating credentials. */ @SuppressWarnings("unchecked") protected boolean authenticateMembership(PeerGroup group, char[] keystorePassword, char[] identityPassword) throws PeerGroupException, ProtocolNotSupportedException { // FIXME: make authentication based on the actual membershipService of the group, not by the provided passwords. String authenticationMethod = null; if (keystorePassword != null && identityPassword != null) { authenticationMethod = "StringAuthentication"; } // private group authentication. if (authenticationMethod != null) { // keystore if (this.localKeystorePassword == null) { // set a keystore pass this.localKeystorePassword = keystorePassword; } else { // see if the keystore pass is good. if (!this.localKeystorePassword.equals(keystorePassword)) { this.logger.error("Can't join the group yet. Keystore password incorrect."); return false; } } // group password. PeerGroupAdvertisement groupAdv = group.getPeerGroupAdvertisement(); StructuredDocument groupPasswordParam = groupAdv .getServiceParam(MockJxtaPeer.groupAuthenticationServiceParamID); Enumeration en = groupPasswordParam.getChildren("groupPassword"); List elements = Collections.list(en); if (elements != null && elements.size() != 0) { Element groupPasswordElement = (Element) elements.get(0); char[] goodGroupPassword = ((String) groupPasswordElement.getValue()).toCharArray(); if (!Arrays.equals(goodGroupPassword, identityPassword)) { this.logger.error("Can't join the group yet. Group password incorrect."); return false; } } else { this.logger.debug("No group password found in the group adv."); } } return true; }