List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:Main.java
public static boolean isCACertificateInstalled(File fileCA, String type, char[] password) throws KeyStoreException { KeyStore keyStoreCA = null;/*from w w w . j a va 2 s .c o m*/ try { keyStoreCA = KeyStore.getInstance(type/*, "BC"*/); } catch (Exception e) { e.printStackTrace(); } if (fileCA.exists() && fileCA.canRead()) { try { FileInputStream fileCert = new FileInputStream(fileCA); keyStoreCA.load(fileCert, password); fileCert.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (java.security.cert.CertificateException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } Enumeration ex = keyStoreCA.aliases(); Date exportFilename = null; String caAliasValue = ""; while (ex.hasMoreElements()) { String is = (String) ex.nextElement(); Date lastStoredDate = keyStoreCA.getCreationDate(is); if (exportFilename == null || lastStoredDate.after(exportFilename)) { exportFilename = lastStoredDate; caAliasValue = is; } } try { return keyStoreCA.getKey(caAliasValue, password) != null; } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnrecoverableKeyException e) { e.printStackTrace(); } } return false; }
From source file:com.arrow.acs.ManifestUtils.java
public static Manifest readManifest(Class<?> clazz) { String method = "readManifest"; String jarFile = null;/* w ww .j a va2 s . c o m*/ String path = clazz.getProtectionDomain().getCodeSource().getLocation().toString(); for (String token : path.split("/")) { token = token.replace("!", "").toLowerCase().trim(); if (token.endsWith(".jar")) { jarFile = token; break; } } LOGGER.logInfo(method, "className: %s, path: %s, jarFile: %s", clazz.getName(), path, jarFile); InputStream is = null; try { if (!StringUtils.isEmpty(jarFile)) { Enumeration<URL> enumeration = Thread.currentThread().getContextClassLoader() .getResources(JarFile.MANIFEST_NAME); while (enumeration.hasMoreElements()) { URL url = enumeration.nextElement(); for (String token : url.toString().split("/")) { token = token.replace("!", "").toLowerCase(); if (token.equals(jarFile)) { LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } } } else { URL url = new URL(path + "/META-INF/MANIFEST.MF"); LOGGER.logInfo(method, "loading manifest from: %s", url.toString()); return new Manifest(is = url.openStream()); } } catch (IOException e) { } finally { IOUtils.closeQuietly(is); } LOGGER.logError(method, "manifest file not found for: %s", clazz.getName()); return null; }
From source file:com.mgmtp.jfunk.core.mail.MessageUtils.java
/** * Returns the specified message as text. * //from w w w .java 2 s .c o m * @param message * the message * @param includeHeaders * specifies whether message headers are to be included in the returned text * @return the message text */ public static String messageAsText(final Message message, final boolean includeHeaders) { try { StrBuilder sb = new StrBuilder(300); if (includeHeaders) { @SuppressWarnings("unchecked") Enumeration<Header> headers = message.getAllHeaders(); while (headers.hasMoreElements()) { Header header = headers.nextElement(); sb.append(header.getName()).append('=').appendln(header.getValue()); } sb.appendln(""); } Object content = message.getContent(); if (content instanceof String) { String body = (String) content; sb.appendln(body); sb.appendln(""); } else if (content instanceof Multipart) { parseMultipart(sb, (Multipart) content); } return sb.toString(); } catch (MessagingException ex) { throw new MailException("Error getting mail content.", ex); } catch (IOException ex) { throw new MailException("Error getting mail content.", ex); } }
From source file:io.card.development.recording.Recording.java
private static Hashtable<String, byte[]> findManifestFiles(Hashtable<String, byte[]> recordingFiles) { Hashtable<String, byte[]> manifestFiles = new Hashtable<String, byte[]>(); Enumeration<String> fileNames = recordingFiles.keys(); while (fileNames.hasMoreElements()) { String fileName = fileNames.nextElement(); if (fileName.endsWith("manifest.json")) { manifestFiles.put(fileName, recordingFiles.get(fileName)); }/* w ww . j a v a 2 s . c o m*/ } return manifestFiles; }
From source file:Main.java
public static <V> List<V> asList(Enumeration<V> elements) { if (elements == null || !elements.hasMoreElements()) { return Collections.emptyList(); }/*from w w w .j ava 2 s . com*/ List<V> copy = new ArrayList<V>(); for (; elements.hasMoreElements();) { copy.add(elements.nextElement()); } return copy; }
From source file:it.geosolutions.sfs.web.Start.java
private static boolean keyStoreContainsCertificate(KeyStore ks, String hostname) throws Exception { // SubjectDnX509PrincipalExtractor ex = new SubjectDnX509PrincipalExtractor(); Enumeration<String> e = ks.aliases(); while (e.hasMoreElements()) { String alias = e.nextElement(); if (ks.isCertificateEntry(alias)) { Certificate c = ks.getCertificate(alias); if (c instanceof X509Certificate) { X500Principal p = (X500Principal) ((X509Certificate) c).getSubjectX500Principal(); if (p.getName().contains(hostname)) return true; }// w w w . j a va 2 s.c om } } return false; }
From source file:io.fabric8.maven.core.util.ClassUtil.java
private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) { Set<String> ret = new HashSet<String>(); while (urlEnum.hasMoreElements()) { ret.add(urlEnum.nextElement().toExternalForm()); }//from w ww. java 2 s .co m return ret; }
From source file:io.galeb.router.sync.HttpClient.java
private static String localIpsEncoded() { final List<String> ipList = new ArrayList<>(); try {/*from w w w .java 2s . co m*/ Enumeration<NetworkInterface> ifs = NetworkInterface.getNetworkInterfaces(); while (ifs.hasMoreElements()) { NetworkInterface localInterface = ifs.nextElement(); if (!localInterface.isLoopback() && localInterface.isUp()) { Enumeration<InetAddress> ips = localInterface.getInetAddresses(); while (ips.hasMoreElements()) { InetAddress ipaddress = ips.nextElement(); if (ipaddress instanceof Inet4Address) { ipList.add(ipaddress.getHostAddress()); break; } } } } } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); } String ip = String.join("-", ipList); if (ip == null || "".equals(ip)) { ip = "undef-" + System.currentTimeMillis(); } return ip.replaceAll("[:%]", ""); }
From source file:net.big_oh.common.web.WebUtil.java
/** * A convenience method that counts number of attributes stored in a user's * {@link HttpSession}./*w w w . j a v a 2 s .com*/ * * @param session * An HttpSession object from any web application. * @return A count of the number of attributes stored in an HttpSession. */ public static int countAttributesInSession(HttpSession session) { int count = 0; Enumeration<?> attributeEnum = session.getAttributeNames(); while (attributeEnum.hasMoreElements()) { attributeEnum.nextElement(); count++; } return count; }
From source file:Main.java
public static String findAppropriateIp() { String result = "unknown"; Enumeration<NetworkInterface> e; try {//from w w w . jav a 2 s .com e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { return result; } while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress inetAddr = ee.nextElement(); String ipAddr = inetAddr.getHostAddress(); Matcher m = ipAddrPattern.matcher(ipAddr); if (m.matches()) { if (!m.group(1).equals("127")) { result = ipAddr; } } } } return result; }