List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:info.magnolia.cms.filters.CosMultipartRequestFilter.java
/** * Adds all request paramaters as request attributes. * @param request HttpServletRequest/* ww w. j a va2s . c o m*/ */ private static MultipartForm parseParameters(HttpServletRequest request) throws IOException { MultipartForm form = new MultipartForm(); String encoding = StringUtils.defaultString(request.getCharacterEncoding(), "UTF-8"); MultipartRequest multi = new MultipartRequest(request, Path.getTempDirectoryPath(), MAX_FILE_SIZE, encoding, null); Enumeration params = multi.getParameterNames(); while (params.hasMoreElements()) { String name = (String) params.nextElement(); String value = multi.getParameter(name); form.addParameter(name, value); String[] s = multi.getParameterValues(name); if (s != null) { form.addparameterValues(name, s); } } Enumeration files = multi.getFileNames(); while (files.hasMoreElements()) { String name = (String) files.nextElement(); form.addDocument(name, multi.getFilesystemName(name), multi.getContentType(name), multi.getFile(name)); } request.setAttribute(MultipartForm.REQUEST_ATTRIBUTE_NAME, form); return form; }
From source file:Main.java
private static String getChannelFromApk(Context context, String channelKey) { ApplicationInfo appinfo = context.getApplicationInfo(); String sourceDir = appinfo.sourceDir; String key = "META-INF/" + channelKey; String ret = ""; ZipFile zipfile = null;//www .j av a 2 s. c o m try { zipfile = new ZipFile(sourceDir); Enumeration<?> entries = zipfile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = ((ZipEntry) entries.nextElement()); String entryName = entry.getName(); if (entryName.startsWith(key)) { ret = entryName; break; } } } catch (IOException e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { e.printStackTrace(); } } } String[] split = ret.split("_"); String channel = ""; if (split != null && split.length >= 2) { channel = ret.substring(split[0].length() + 1); } return channel; }
From source file:com.servoy.j2db.server.ngclient.startup.resourceprovider.ComponentResourcesExporter.java
/** * @param path//from w ww. j av a 2s.co m * @param tmpWarDir * @throws IOException */ private static void copy(Enumeration<String> paths, File destDir) throws IOException { if (paths != null) { while (paths.hasMoreElements()) { String path = paths.nextElement(); if (path.endsWith("/")) { File targetDir = new File(destDir, FilenameUtils.getName(path.substring(0, path.lastIndexOf("/")))); copy(Activator.getContext().getBundle().getEntryPaths(path), targetDir); } else { URL entry = Activator.getContext().getBundle().getEntry(path); FileUtils.copyInputStreamToFile(entry.openStream(), new File(destDir, FilenameUtils.getName(path))); } } } }
From source file:eurecom.constrained.devices.ReadZipFile.java
public static void unzip(final ZipFile zipfile, final File directory) throws IOException { final Enumeration<? extends ZipEntry> entries = zipfile.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); final File file = file(directory, entry); if (entry.isDirectory()) { continue; }// w w w . ja v a2 s .com final InputStream input = zipfile.getInputStream(entry); try { // copy bytes from input to file } finally { input.close(); } } }
From source file:it.greenvulcano.gvesb.adapter.http.utils.DumpUtils.java
public static void dump(HttpServletRequest request, StringBuffer log) throws IOException { String hN;/*from w w w .j a va2 s. co m*/ log.append("-- DUMP HttpServletRequest START").append("\n"); log.append("Method : ").append(request.getMethod()).append("\n"); log.append("RequestedSessionId : ").append(request.getRequestedSessionId()).append("\n"); log.append("Scheme : ").append(request.getScheme()).append("\n"); log.append("IsSecure : ").append(request.isSecure()).append("\n"); log.append("Protocol : ").append(request.getProtocol()).append("\n"); log.append("ContextPath : ").append(request.getContextPath()).append("\n"); log.append("PathInfo : ").append(request.getPathInfo()).append("\n"); log.append("QueryString : ").append(request.getQueryString()).append("\n"); log.append("RequestURI : ").append(request.getRequestURI()).append("\n"); log.append("RequestURL : ").append(request.getRequestURL()).append("\n"); log.append("ContentType : ").append(request.getContentType()).append("\n"); log.append("ContentLength : ").append(request.getContentLength()).append("\n"); log.append("CharacterEncoding : ").append(request.getCharacterEncoding()).append("\n"); log.append("---- Headers START\n"); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { hN = headerNames.nextElement(); log.append("[" + hN + "]="); Enumeration<String> headers = request.getHeaders(hN); while (headers.hasMoreElements()) { log.append("[" + headers.nextElement() + "]"); } log.append("\n"); } log.append("---- Headers END\n"); log.append("---- Body START\n"); log.append(IOUtils.toString(request.getInputStream())).append("\n"); log.append("---- Body END\n"); log.append("-- DUMP HttpServletRequest END \n"); }
From source file:Main.java
/** * Check whether the given Enumeration contains the given element. * * @param enumeration the Enumeration to check * @param element the element to look for * @return {@code true} if found, {@code false} else *//*from w w w . jav a2 s . c o m*/ public static boolean contains(Enumeration<?> enumeration, Object element) { if (enumeration != null) { while (enumeration.hasMoreElements()) { Object candidate = enumeration.nextElement(); if (ObjectUtils.nullSafeEquals(candidate, element)) { return true; } } } return false; }
From source file:Main.java
public static String getIPAddr() { try {//from w w w .j av a 2 s.com Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface networkInterface = networkInterfaces.nextElement(); Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); return inetAddress.getHostAddress().toString(); } } } catch (SocketException e) { e.printStackTrace(); } return null; }
From source file:com.cloudbees.jenkins.support.impl.RootCAs.java
public static void getRootCAList(StringWriter writer) { KeyStore instance = null;// w ww . ja v a 2 s . co m try { instance = KeyStore.getInstance(KeyStore.getDefaultType()); Enumeration<String> aliases = instance.aliases(); while (aliases.hasMoreElements()) { String s = aliases.nextElement(); writer.append("========"); writer.append("Alias: " + s); writer.append(instance.getCertificate(s).getPublicKey().toString()); writer.append("Trusted certificate: " + instance.isCertificateEntry(s)); } } catch (KeyStoreException e) { writer.write(Functions.printThrowable(e)); } }
From source file:com.microsoft.aad.adal4j.MSCAPIAsymmetricKeyCredential.java
/** * Static method to create KeyCredential instance. * /*w w w . jav a 2 s . c o m*/ * @param clientId * Identifier of the client requesting the token. * @param pkcs12Certificate * PKCS12 certificate stream containing public and private key. * Caller is responsible to handling the inputstream. * @param password * certificate password * @return KeyCredential instance * @throws KeyStoreException * @throws NoSuchProviderException * @throws NoSuchAlgorithmException * @throws CertificateException * @throws FileNotFoundException * @throws IOException * @throws UnrecoverableKeyException */ public static MSCAPIAsymmetricKeyCredential create(final String clientId, final InputStream pkcs12Certificate, final String password) throws KeyStoreException, NoSuchProviderException, NoSuchAlgorithmException, CertificateException, FileNotFoundException, IOException, UnrecoverableKeyException { final KeyStore keystore = KeyStore.getInstance("PKCS12", "SunJSSE"); keystore.load(pkcs12Certificate, password.toCharArray()); final Enumeration<String> aliases = keystore.aliases(); final String alias = aliases.nextElement(); final PrivateKey key = (PrivateKey) keystore.getKey(alias, password.toCharArray()); final X509Certificate publicCertificate = (X509Certificate) keystore.getCertificate(alias); return create(clientId, key, publicCertificate); }
From source file:Main.java
public static JComponent makeUI() { JTree tree = new JTree(); TreeModel model = tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); Enumeration e = root.breadthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); Object o = node.getUserObject(); if (o instanceof String) { node.setUserObject(new CheckBoxNode((String) o, false)); }//from www . ja v a 2s . c o m } tree.setEditable(true); tree.setCellRenderer(new CheckBoxNodeRenderer()); tree.setCellEditor(new CheckBoxNodeEditor()); tree.expandRow(0); return new JScrollPane(tree); }