List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:org.paxml.bean.UnzipTag.java
public static void unzip(File file, File dir) { dir.mkdirs();/*from ww w . j a v a2s . c om*/ ZipFile zipFile = null; try { zipFile = new ZipFile(file); Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { new File(dir, entry.getName()).mkdirs(); continue; } InputStream in = null; OutputStream out = null; try { zipFile.getInputStream(entry); out = new BufferedOutputStream(new FileOutputStream(entry.getName())); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } catch (IOException ioe) { throw new PaxmlRuntimeException( "Cannot unzip file: " + file.getAbsolutePath() + " under dir: " + dir.getAbsolutePath(), ioe); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { // do nothing } } } }
From source file:com.google.gdt.eclipse.designer.webkit.WebKitSupportWin32.java
private static void extract(ZipFile zipFile) throws Exception { // remove any possibly corrupted contents FileUtils.deleteQuietly(WEBKIT_DIR); WEBKIT_DIR.mkdirs();//from w ww. j a va 2s. c o m Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { new File(WEBKIT_DIR, entry.getName()).mkdirs(); continue; } InputStream inputStream = zipFile.getInputStream(entry); File outputFile = new File(WEBKIT_DIR, entry.getName()); FileOutputStream outputStream = new FileOutputStream(outputFile); IOUtils.copy(inputStream, outputStream); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(outputStream); } }
From source file:gov.va.oia.terminology.converters.sharedUtils.Unzip.java
public final static void unzip(File zipFile, File rootDir) throws IOException { ZipFile zip = new ZipFile(zipFile); @SuppressWarnings("unchecked") Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); java.io.File f = new java.io.File(rootDir, entry.getName()); if (entry.isDirectory()) { f.mkdirs();/*from www .j av a2 s. c o m*/ continue; } else { f.createNewFile(); } InputStream is = null; OutputStream os = null; try { is = zip.getInputStream(entry); os = new FileOutputStream(f); IOUtils.copy(is, os); } finally { if (is != null) { try { is.close(); } catch (Exception e) { // noop } } if (os != null) { try { os.close(); } catch (Exception e) { // noop } } } } zip.close(); }
From source file:Main.java
public static Collection<InetAddress> getAllAvailableAddresses() { Set<InetAddress> retval = new HashSet<InetAddress>(); Enumeration en; try {//from w ww.ja v a 2 s . co m en = NetworkInterface.getNetworkInterfaces(); if (en == null) return retval; while (en.hasMoreElements()) { NetworkInterface intf = (NetworkInterface) en.nextElement(); Enumeration<InetAddress> addrs = intf.getInetAddresses(); while (addrs.hasMoreElements()) retval.add(addrs.nextElement()); } } catch (SocketException e) { e.printStackTrace(); } return retval; }
From source file:com.apifest.oauth20.LifecycleEventHandlers.java
@SuppressWarnings("unchecked") public static void loadLifecycleHandlers(URLClassLoader classLoader, String customJar) { try {// www . ja va 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.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 {/*www . ja v a 2 s . com*/ 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 ww . jav a2 s .co m*/ * @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:Main.java
public static String enumerationToString(Enumeration enm) { StringBuffer sb = new StringBuffer(100); boolean firstItem = true; sb.append("["); while (enm.hasMoreElements()) { if (!firstItem) { sb.append(", "); }// w ww . ja v a2s .c o m sb.append(enm.nextElement()); firstItem = false; } sb.append("]"); return sb.toString(); }
From source file:Main.java
/** * extracts a zip file to the given dir/* w ww .ja va2s . c o m*/ * @param archive * @param destDir * @throws IOException * @throws ZipException * @throws Exception */ public static void extractZipArchive(File archive, File destDir) throws ZipException, IOException { if (!destDir.exists()) { destDir.mkdir(); } ZipFile zipFile = new ZipFile(archive); Enumeration<? extends ZipEntry> entries = zipFile.entries(); byte[] buffer = new byte[16384]; int len; while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String entryFileName = entry.getName(); File dir = buildDirectoryHierarchyFor(entryFileName, destDir); if (!dir.exists()) { dir.mkdirs(); } if (!entry.isDirectory()) { BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(new File(destDir, entryFileName))); BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); while ((len = bis.read(buffer)) > 0) { bos.write(buffer, 0, len); } bos.flush(); bos.close(); bis.close(); } } }
From source file:com.frostwire.util.VPNs.java
public static void printNetworkInterfaces() { try {//from w ww.j a v a 2 s.c om Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); while (networkInterfaces.hasMoreElements()) { NetworkInterface iface = networkInterfaces.nextElement(); System.out.println(iface.getIndex() + ":" + iface.getDisplayName() + ":" + "virtual=" + iface.isVirtual() + ":" + "mtu=" + iface.getMTU() + ":mac=" + (iface.getHardwareAddress() != null ? "0x" + ByteUtils.encodeHex(iface.getHardwareAddress()) : "n/a")); } } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } }