List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:net.centro.rtb.monitoringcenter.infos.NodeInfo.java
private static String detectLoadBalancerIpAddress() { Enumeration<NetworkInterface> networkInterfaces = null; try {// ww w . j ava2s . com networkInterfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { logger.debug("Unable to obtain network interfaces!", e); return null; } for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { boolean isLoopback = false; try { isLoopback = networkInterface.isLoopback(); } catch (SocketException e) { logger.debug("Unable to identify if a network interface is a loopback or not"); continue; } if (isLoopback) { Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); if (!inetAddress.isLoopbackAddress() && Inet4Address.class.isInstance(inetAddress)) { return inetAddress.getHostAddress(); } } } } return null; }
From source file:com.mc.printer.model.utils.ZipHelper.java
public static void unZip(String sourceZip, String outDirName) throws IOException { log.info("unzip source:" + sourceZip); log.info("unzip to :" + outDirName); ZipFile zfile = new ZipFile(sourceZip); System.out.println(zfile.getName()); Enumeration zList = zfile.entries(); ZipEntry ze = null;/*from w ww .j a v a 2s . c o m*/ byte[] buf = new byte[1024]; while (zList.hasMoreElements()) { //ZipFileZipEntry ze = (ZipEntry) zList.nextElement(); if (ze.isDirectory()) { continue; } //ZipEntry?InputStreamOutputStream File fil = getRealFileName(outDirName, ze.getName()); OutputStream os = new BufferedOutputStream(new FileOutputStream(fil)); InputStream is = new BufferedInputStream(zfile.getInputStream(ze)); int readLen = 0; while ((readLen = is.read(buf, 0, 1024)) != -1) { os.write(buf, 0, readLen); } is.close(); os.close(); log.debug("Extracted: " + ze.getName()); } zfile.close(); }
From source file:com.ai.smart.common.helper.util.RequestUtils.java
private static Map<String, String> getRequestMap(HttpServletRequest request, String prefix, boolean nameWithPrefix) { Map<String, String> map = new HashMap<String, String>(); Enumeration<String> names = request.getParameterNames(); String name, key, value;// w ww . j a va 2 s . com while (names.hasMoreElements()) { name = names.nextElement(); if (name.startsWith(prefix)) { key = nameWithPrefix ? name : name.substring(prefix.length()); value = StringUtils.join(request.getParameterValues(name), ','); map.put(key, value); } } return map; }
From source file:de.micromata.genome.logging.LogRequestDumpAttribute.java
/** * Gen http request dump./*from w w w. jav a 2 s . c o m*/ * * @param req the req * @return the string */ @SuppressWarnings("unchecked") public static String genHttpRequestDump(HttpServletRequest req) { StringBuilder sb = new StringBuilder(); sb.append("method: ").append(req.getMethod()).append('\n')// .append("requestURL: ").append(req.getRequestURL()).append('\n')// .append("servletPath: ").append(req.getServletPath()).append('\n')// .append("requestURI: ").append(req.getRequestURI()).append('\n') // .append("queryString: ").append(req.getQueryString()).append('\n') // .append("pathInfo: ").append(req.getPathInfo()).append('\n')// .append("contextPath: ").append(req.getContextPath()).append('\n') // .append("characterEncoding: ").append(req.getCharacterEncoding()).append('\n') // .append("localName: ").append(req.getLocalName()).append('\n') // .append("contentLength: ").append(req.getContentLength()).append('\n') // ; sb.append("Header:\n"); for (Enumeration<String> en = req.getHeaderNames(); en.hasMoreElements();) { String hn = en.nextElement(); sb.append(" ").append(hn).append(": ").append(req.getHeader(hn)).append("\n"); } sb.append("Attr: \n"); Enumeration en = req.getAttributeNames(); for (; en.hasMoreElements();) { String k = (String) en.nextElement(); Object v = req.getAttribute(k); sb.append(" ").append(k).append(": ").append(Objects.toString(v, StringUtils.EMPTY)).append('\n'); } return sb.toString(); }
From source file:de.xwic.appkit.core.util.ZipUtil.java
/** * Unzips the files from the zipped file into the destination folder. * //from www .j a v a 2 s. co m * @param zippedFile * the files array * @param destinationFolder * the folder in which the zip archive will be unzipped * @return the file array which consists into the files which were zipped in * the zippedFile * @throws IOException */ public static File[] unzip(File zippedFile, String destinationFolder) throws IOException { ZipFile zipFile = null; List<File> files = new ArrayList<File>(); try { zipFile = new ZipFile(zippedFile); Enumeration<?> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (!entry.isDirectory()) { String filePath = destinationFolder + System.getProperty("file.separator") + entry.getName(); FileOutputStream stream = new FileOutputStream(filePath); InputStream is = zipFile.getInputStream(entry); log.info("Unzipping " + entry.getName()); int n = 0; while ((n = is.read(BUFFER)) > 0) { stream.write(BUFFER, 0, n); } is.close(); stream.close(); files.add(new File(filePath)); } } zipFile.close(); } catch (IOException e) { log.error("Error: " + e.getMessage(), e); throw e; } finally { try { if (null != zipFile) { zipFile.close(); } } catch (IOException e) { log.error("Error: " + e.getMessage(), e); throw e; } } File[] array = files.toArray(new File[files.size()]); return array; }
From source file:in.xebia.poc.FileUploadUtils.java
public static boolean parseFileUploadRequest(HttpServletRequest request, File outputFile, Map<String, String> params) throws Exception { log.debug("Request class? " + request.getClass().toString()); log.debug("Request is multipart? " + ServletFileUpload.isMultipartContent(request)); log.debug("Request method: " + request.getMethod()); log.debug("Request params: "); for (Object key : request.getParameterMap().keySet()) { log.debug((String) key);//from w w w .j a v a 2 s . co m } log.debug("Request attribute names: "); boolean filedataInAttributes = false; Enumeration attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); log.debug(attrName); if ("filedata".equals(attrName)) { filedataInAttributes = true; } } if (filedataInAttributes) { log.debug("Found filedata in request attributes, getting it out..."); log.debug("filedata class? " + request.getAttribute("filedata").getClass().toString()); FileItem item = (FileItem) request.getAttribute("filedata"); item.write(outputFile); for (Object key : request.getParameterMap().keySet()) { params.put((String) key, request.getParameter((String) key)); } return true; } /*ServletFileUpload upload = new ServletFileUpload(); //upload.setSizeMax(Globals.MAX_UPLOAD_SIZE); FileItemIterator iter = upload.getItemIterator(request); while(iter.hasNext()){ FileItemStream item = iter.next(); InputStream stream = item.openStream(); //If this item is a file if(!item.isFormField()){ log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if(name == null){ throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); //Enforce required file extension, if present if(!name.toLowerCase().endsWith( ".zip" )){ throw new Exception("File uploaded did not have required extension .zip"); } bufferedCopyStream(stream, new FileOutputStream(outputFile)); } else { params.put(item.getFieldName(), Streams.asString(stream)); } } return true;*/ // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List /* FileItem */ items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (!item.isFormField()) { log.debug("Found non form field in upload request with field name = " + item.getFieldName()); String name = item.getName(); if (name == null) { throw new Exception("File upload did not have filename specified"); } // Some browsers, including IE, return the full path so trim off everything but the file name name = getFileNameFromPath(name); item.write(outputFile); } else { params.put(item.getFieldName(), item.getString()); } } return true; }
From source file:net.centro.rtb.monitoringcenter.infos.NodeInfo.java
private static String detectPublicIpAddress() { Enumeration<NetworkInterface> networkInterfaces = null; try {//from www .j a v a 2 s . c o m networkInterfaces = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { logger.debug("Unable to obtain network interfaces!", e); return null; } for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) { boolean isLoopback = false; try { isLoopback = networkInterface.isLoopback(); } catch (SocketException e) { logger.debug("Unable to identify if a network interface is a loopback or not"); } if (!isLoopback) { Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); if (Inet4Address.class.isInstance(inetAddress)) { if (!inetAddress.isLoopbackAddress() && !inetAddress.isAnyLocalAddress() && !inetAddress.isLinkLocalAddress() && !inetAddress.isSiteLocalAddress()) { return inetAddress.getHostAddress(); } } } } } return null; }
From source file:io.card.development.recording.ManifestEntry.java
public static ManifestEntry[] getManifest(Hashtable<String, byte[]> recordingData) { Enumeration<String> keys = recordingData.keys(); String manifestKey = null;//from w ww. ja va 2 s . c o m while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.endsWith("manifest.json")) { manifestKey = key; break; } } if (manifestKey == null) { return null; } String manifestDirName = manifestKey.substring(0, manifestKey.lastIndexOf("/")); String manifestString = new String(recordingData.get(manifestKey)); JSONArray manifestData; try { manifestData = new JSONArray(manifestString); } catch (JSONException e1) { Log.e(TAG, "Exception parsing JSON array: " + e1.getMessage()); return null; } ManifestEntry[] manifest = new ManifestEntry[manifestData.length()]; for (int i = 0; i < manifestData.length(); i++) { try { JSONObject jo = manifestData.getJSONObject(i); manifest[i] = new ManifestEntry(manifestDirName, jo, recordingData); } catch (JSONException e) { Log.e(TAG, "Couldn't parse JSON: " + e.getMessage()); } } return manifest; }
From source file:SerialVersionUID.java
/** * Build a TreeMap of the class name to ClassVersionInfo * /*from ww w .j av a2s. co m*/ * @param jar * @param classVersionMap * TreeMap<String, ClassVersionInfo> for serializable classes * @param cl - * the class loader to use * @throws IOException * thrown if the jar cannot be opened */ static void generateJarSerialVersionUIDs(URL jar, TreeMap classVersionMap, ClassLoader cl, String pkgPrefix) throws IOException { String jarName = jar.getFile(); JarFile jf = new JarFile(jarName); Enumeration entries = jf.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); String name = entry.getName(); if (name.endsWith(".class") && name.startsWith(pkgPrefix)) { name = name.substring(0, name.length() - 6); String classname = name.replace('/', '.'); try { log.fine("Creating ClassVersionInfo for: " + classname); ClassVersionInfo cvi = new ClassVersionInfo(classname, cl); log.fine(cvi.toString()); if (cvi.getSerialVersion() != 0) { ClassVersionInfo prevCVI = (ClassVersionInfo) classVersionMap.put(classname, cvi); if (prevCVI != null) { if (prevCVI.getSerialVersion() != cvi.getSerialVersion()) { log.severe("Found inconsistent classes, " + prevCVI + " != " + cvi + ", jar: " + jarName); } } if (cvi.getHasExplicitSerialVersionUID() == false) { log.warning("No explicit serialVersionUID: " + cvi); } } } catch (OutOfMemoryError e) { log.log(Level.SEVERE, "Check the MaxPermSize", e); } catch (Throwable e) { log.log(Level.FINE, "While loading: " + name, e); } } } jf.close(); }