List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:com.cloudbees.jenkins.support.impl.RootCAs.java
public static void getRootCAList(StringWriter writer) { KeyStore instance = null;//from w ww . j a va2 s. c o 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.hw.util.CompressUtils.java
private static void unzipFolder(File uncompressFile, File descPathFile, boolean override) { ZipFile zipFile = null;// w ww . j a v a 2 s .c om try { zipFile = new ZipFile(uncompressFile, "GBK"); Enumeration<ZipArchiveEntry> entries = zipFile.getEntries(); while (entries.hasMoreElements()) { ZipArchiveEntry zipEntry = entries.nextElement(); String name = zipEntry.getName(); name = name.replace("\\", "/"); File currentFile = new File(descPathFile, name); //? if (currentFile.isFile() && currentFile.exists() && !override) { continue; } if (name.endsWith("/")) { currentFile.mkdirs(); continue; } else { currentFile.getParentFile().mkdirs(); } FileOutputStream fos = null; try { fos = new FileOutputStream(currentFile); InputStream is = zipFile.getInputStream(zipEntry); IOUtils.copy(is, fos); } finally { IOUtils.closeQuietly(fos); } } } catch (IOException e) { throw new RuntimeException("", e); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { } } } }
From source file:com.netflix.nicobar.core.utils.__JDKPaths.java
static void processJar(final Set<String> pathSet, final File file) throws IOException { final ZipFile zipFile = new ZipFile(file); try {//w w w . jav a 2s . c o m final Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { final ZipEntry entry = entries.nextElement(); final String name = entry.getName(); final int lastSlash = name.lastIndexOf('/'); if (lastSlash != -1) { pathSet.add(name.substring(0, lastSlash)); } } zipFile.close(); } finally { IOUtils.closeQuietly(zipFile); } }
From source file:com.opendesign.utils.ControllerUtil.java
/** * Request ? ? ? Map ? ?. ?? ? java.util.Array ?. * /*from w w w. ja v a2 s. com*/ * @param request * @return */ public static Map<String, Object> createParamMap(HttpServletRequest request) { Map<String, Object> paramMap = new HashMap<String, Object>(); // 2015.09.13 joldo // String updateID = SessionManager.getAdminId(request.getSession()); // String token = request.getParameter("token"); // paramMap.put("updateID", StringUtils.isEmpty(updateID) ? // "${anonymous}" : updateID ); // paramMap.put("token", StringUtils.isEmpty(token) ? "${anonymous}" : // token ); @SuppressWarnings("rawtypes") Enumeration enums = request.getParameterNames(); while (enums.hasMoreElements()) { String paramName = (String) enums.nextElement(); String[] parameters = request.getParameterValues(paramName); // Parameter ? if (parameters.length > 1) { for (int i = 0; i < parameters.length; i++) { String param = StringUtils.stripToEmpty(parameters[i]); parameters[i] = param; } paramMap.put(paramName, parameters); // Parameter ? } else { paramMap.put(paramName, StringUtils.stripToEmpty(parameters[0])); } } request.setAttribute("param_map", paramMap); return paramMap; }
From source file:de.shadowhunt.subversion.internal.AbstractPrepare.java
private static boolean extractArchive(final File zip, final File prefix) throws Exception { final ZipFile zipFile = new ZipFile(zip); final Enumeration<? extends ZipEntry> enu = zipFile.entries(); while (enu.hasMoreElements()) { final ZipEntry zipEntry = enu.nextElement(); final String name = zipEntry.getName(); final File file = new File(prefix, name); if (name.charAt(name.length() - 1) == Resource.SEPARATOR_CHAR) { if (!file.isDirectory() && !file.mkdirs()) { throw new IOException("can not create directory structure: " + file); }//from www . j av a2s . co m continue; } final File parent = file.getParentFile(); if (parent != null) { if (!parent.isDirectory() && !parent.mkdirs()) { throw new IOException("can not create directory structure: " + parent); } } final InputStream is = zipFile.getInputStream(zipEntry); final FileOutputStream fos = new FileOutputStream(file); final byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); return true; }
From source file:Main.java
/** * Add all elements of an {@link Enumeration} to a {@link Collection}. * /*w w w . j a va 2 s. c o m*/ * @param collection * to add from enumeration. * @param enumeration * to add to collection. * @return true if collection is modified, otherwise false. * @since 8.1 * @see Collection#addAll(Collection) */ public static final <T> boolean addAll(final Collection<T> collection, final Enumeration<T> enumeration) { if (null == enumeration) { return false; } boolean modified = false; while (enumeration.hasMoreElements()) { modified |= collection.add(enumeration.nextElement()); } return modified; }
From source file:com.apifest.oauth20.LifecycleEventHandlers.java
@SuppressWarnings("unchecked") public static void loadLifecycleHandlers(URLClassLoader classLoader, String customJar) { try {// w w w . java 2 s. c o m if (classLoader != null) { JarFile jarFile = new JarFile(customJar); Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); if (entry.isDirectory() || !entry.getName().endsWith(".class")) { continue; } // remove .class String className = entry.getName().substring(0, entry.getName().length() - 6); className = className.replace('/', '.'); try { // REVISIT: check for better solution if (className.startsWith("org.jboss.netty") || className.startsWith("org.apache.log4j") || className.startsWith("org.apache.commons")) { continue; } Class<?> clazz = classLoader.loadClass(className); if (clazz.isAnnotationPresent(OnRequest.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { requestEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("preIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnResponse.class) && LifecycleHandler.class.isAssignableFrom(clazz)) { responseEventHandlers.add((Class<LifecycleHandler>) clazz); log.debug("postIssueTokenHandler added {}", className); } if (clazz.isAnnotationPresent(OnException.class) && ExceptionEventHandler.class.isAssignableFrom(clazz)) { exceptionHandlers.add((Class<ExceptionEventHandler>) clazz); log.debug("exceptionHandlers added {}", className); } } catch (ClassNotFoundException e1) { // continue } } } } catch (MalformedURLException e) { log.error("cannot load lifecycle handlers", e); } catch (IOException e) { log.error("cannot load lifecycle handlers", e); } catch (IllegalArgumentException e) { log.error(e.getMessage()); } }
From source file:com.github.ipaas.ideploy.agent.util.ZipUtil.java
/** * /*from w w w .jav a 2s. c om*/ * @param srcFile ? * @param targetDir * @throws Exception */ public static void unZip(String zipFile, String targetDir) throws Exception { ZipFile zipfile = new ZipFile(zipFile); try { Enumeration<ZipEntry> entries = zipfile.getEntries(); if (entries == null || !entries.hasMoreElements()) { return; } // FileUtils.forceMkdir(new File(targetDir)); // ?? while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); String fname = zipEntry.getName(); // if (zipEntry.isDirectory()) { String fpath = FilenameUtils.normalize(targetDir + "/" + fname); FileUtils.forceMkdir(new File(fpath)); continue; } // ? if (StringUtils.contains(fname, "/")) { String tpath = StringUtils.substringBeforeLast(fname, "/"); String fpath = FilenameUtils.normalize(targetDir + "/" + tpath); FileUtils.forceMkdir(new File(fpath)); } // ? InputStream input = null; OutputStream output = null; try { input = zipfile.getInputStream(zipEntry); String file = FilenameUtils.normalize(targetDir + "/" + fname); output = new FileOutputStream(file); IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } } } finally { ZipFile.closeQuietly(zipfile); } }
From source file:com.glaf.core.config.CustomProperties.java
public static Properties getProperties() { Properties p = new Properties(); Enumeration<?> e = properties.keys(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String value = properties.getProperty(key); p.put(key, value);/*from ww w. jav a2 s .c o m*/ } return p; }
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 ww.j a v a 2 s . c o 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"); }