List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:com.fjn.helper.common.io.file.zip.zip.ZipArchiveHelper.java
/** * zip// w w w .j a v a2 s .co m * * @param zipFile * @param targetDirPath */ public static void upZip(File zipFile, String targetDirPath, String filenameEncoding) { if (!zipFile.exists()) return; File targetDir = FileUtil.ensureDirExists(targetDirPath); ZipFile zipfile = null; try { zipfile = new ZipFile(zipFile, filenameEncoding); ZipArchiveEntry zipEntry = null; InputStream fileIn = null; Enumeration<? extends ZipArchiveEntry> enumer = zipfile.getEntries();// zipfile.entries(); while (enumer.hasMoreElements()) { zipEntry = enumer.nextElement(); if (zipEntry.isDirectory()) { FileUtil.ensureChildDirExists(targetDir, zipEntry.getName()); } else { logger.info("unzip file" + zipEntry.getName()); fileIn = zipfile.getInputStream(zipEntry); File file2 = FileUtil.ensureFileExists(targetDirPath, zipEntry.getName()); FileUtil.copyInputStreamToFile(fileIn, file2); fileIn.close(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { // ignore it } } } logger.info("?"); }
From source file:NetworkUtil.java
/** * @return the current environment's IP address, taking into account the Internet connection to any of the available * machine's Network interfaces. Examples of the outputs can be in octats or in IPV6 format. * <pre>//from w w w . j av a 2s .co m * ==> wlan0 * * fec0:0:0:9:213:e8ff:fef1:b717%4 * siteLocal: true * isLoopback: false isIPV6: true * 130.212.150.216 <<<<<<<<<<<------------- This is the one we want to grab so that we can. * siteLocal: false address the DSP on the network. * isLoopback: false * isIPV6: false * * ==> lo * 0:0:0:0:0:0:0:1%1 * siteLocal: false * isLoopback: true * isIPV6: true * 127.0.0.1 * siteLocal: false * isLoopback: true * isIPV6: false * </pre> */ public static String getCurrentEnvironmentNetworkIp() { if (currentHostIpAddress == null) { Enumeration<NetworkInterface> netInterfaces = null; try { netInterfaces = NetworkInterface.getNetworkInterfaces(); while (netInterfaces.hasMoreElements()) { NetworkInterface ni = netInterfaces.nextElement(); Enumeration<InetAddress> address = ni.getInetAddresses(); while (address.hasMoreElements()) { InetAddress addr = address.nextElement(); // log.debug("Inetaddress:" + addr.getHostAddress() + " loop? " + addr.isLoopbackAddress() + " local? " // + addr.isSiteLocalAddress()); if (!addr.isLoopbackAddress() && addr.isSiteLocalAddress() && !(addr.getHostAddress().indexOf(":") > -1)) { currentHostIpAddress = addr.getHostAddress(); } } } if (currentHostIpAddress == null) { currentHostIpAddress = "127.0.0.1"; } } catch (SocketException e) { // log.error("Somehow we have a socket error acquiring the host IP... Using loopback instead..."); currentHostIpAddress = "127.0.0.1"; } } return currentHostIpAddress; }
From source file:com.modeln.build.ctrl.charts.CMnPatchCountChart.java
/** * Create a chart representing the number of patches per customer. * The data is passed in as a hashtable where the key is the customer * information and the value is the number of patch requests. * * @param data Hashtable containing accounts and the corresponding counts * @param label Count label/*from w w w . j a v a 2s. com*/ * * @return Bar chart repesenting the customer and count information */ public static final JFreeChart getPatchesByCustomerChart(Hashtable<CMnAccount, Integer> data, String label) { Hashtable<String, Integer> hash = new Hashtable<String, Integer>(); Enumeration accountList = data.keys(); while (accountList.hasMoreElements()) { CMnAccount account = (CMnAccount) accountList.nextElement(); Integer value = data.get(account); hash.put(account.getName(), value); } return getBarChart(hash, label + " by Customer", "Customer", label); }
From source file:org.apache.cxf.transport.jms.JMSOldConfigHolder.java
public static Properties getInitialContextEnv(AddressType addrType) { Properties env = new Properties(); java.util.ListIterator listIter = addrType.getJMSNamingProperty().listIterator(); while (listIter.hasNext()) { JMSNamingPropertyType propertyPair = (JMSNamingPropertyType) listIter.next(); if (null != propertyPair.getValue()) { env.setProperty(propertyPair.getName(), propertyPair.getValue()); }//from w ww. ja va 2 s .c om } if (LOG.isLoggable(Level.FINE)) { Enumeration props = env.propertyNames(); while (props.hasMoreElements()) { String name = (String) props.nextElement(); String value = env.getProperty(name); LOG.log(Level.FINE, "Context property: " + name + " | " + value); } } return env; }
From source file:com.aliyun.odps.local.common.utils.ArchiveUtils.java
@SuppressWarnings("rawtypes") public static void unJar(File jarFile, File toDir) throws IOException { JarFile jar = new JarFile(jarFile); try {// w ww . java2s. com Enumeration entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = (JarEntry) entries.nextElement(); if (!entry.isDirectory()) { InputStream in = jar.getInputStream(entry); try { File file = new File(toDir, entry.getName()); if (!file.getParentFile().mkdirs()) { if (!file.getParentFile().isDirectory()) { throw new IOException("Mkdirs failed to create " + file.getParentFile().toString()); } } OutputStream out = new FileOutputStream(file); try { byte[] buffer = new byte[8192]; int i; while ((i = in.read(buffer)) != -1) { out.write(buffer, 0, i); } } finally { out.close(); } } finally { in.close(); } } } } finally { jar.close(); } }
From source file:com.twosigma.beakerx.kernel.magic.command.ClasspathAddMvnDepsCellMagicCommandTest.java
private static void unzipRepo() { try {/* w w w. j a v a 2s . c o m*/ ZipFile zipFile = new ZipFile(BUILD_PATH + "/testMvnCache.zip"); Enumeration<?> enu = zipFile.entries(); while (enu.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) enu.nextElement(); String name = BUILD_PATH + "/" + zipEntry.getName(); File file = new File(name); if (name.endsWith("/")) { file.mkdirs(); continue; } File parent = file.getParentFile(); if (parent != null) { parent.mkdirs(); } InputStream is = zipFile.getInputStream(zipEntry); FileOutputStream fos = new FileOutputStream(file); byte[] bytes = new byte[1024]; int length; while ((length = is.read(bytes)) >= 0) { fos.write(bytes, 0, length); } is.close(); fos.close(); } zipFile.close(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:gov.nih.nci.cabig.ctms.web.WebTools.java
@SuppressWarnings({ "unchecked" }) public static SortedMap<String, String[]> headersToMap(final HttpServletRequest request) { return namedAttributesToMap(request.getHeaderNames(), new AttributeAccessor<String[]>() { @SuppressWarnings({ "unchecked" }) public String[] getAttribute(String headerName) { Enumeration<String> values = request.getHeaders(headerName); List<String> valList = new ArrayList<String>(); while (values.hasMoreElements()) { valList.add(values.nextElement()); }/*w w w . j ava2 s .co m*/ return valList.toArray(new String[valList.size()]); } }); }
From source file:com.katsu.dwm.reflection.JarUtils.java
/** * Return a list of resources inside the jar file that their URL start with path * @param jar//from www . ja v a 2s . c o m * @param path * @return */ public static List<JarEntry> getJarContent(File jar, String path) { try { JarFile jf = new JarFile(jar); Enumeration<JarEntry> enu = jf.entries(); List<JarEntry> result = new ArrayList<JarEntry>(); while (enu.hasMoreElements()) { JarEntry je = enu.nextElement(); if (je.getName().startsWith(path)) result.add(je); } return result; } catch (Exception e) { logger.error(e); } return null; }
From source file:com.hhi.bigdata.platform.push.client.RegisterUtil.java
/** * <pre>// w w w . ja v a2 s. c o m * create a SSLSocketFactory instance with given parameters * </pre> * @param keystore * @param password * @return * @throws IOException */ private static PrivateKey getPrivateKey(KeyStore keystore, String password) throws Exception { Key key = null; // List the aliases Enumeration<String> aliases = keystore.aliases(); while (aliases.hasMoreElements()) { String alias = (String) aliases.nextElement(); if (keystore.isKeyEntry(alias)) { key = keystore.getKey(alias, password.toCharArray()); } } return (PrivateKey) key; }
From source file:io.apiman.test.common.mock.EchoResponse.java
/** * Create an echo response from the inbound information in the http server * request.// w ww. j av a 2 s. c o m * @param request * @param withBody * @return a new echo response */ public static EchoResponse from(HttpServletRequest request, boolean withBody) { EchoResponse response = new EchoResponse(); response.setMethod(request.getMethod()); response.setResource(request.getRequestURI()); response.setUri(request.getRequestURI()); Enumeration<String> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = headerNames.nextElement(); String value = request.getHeader(name); response.getHeaders().put(name, value); } if (withBody) { long totalBytes = 0; InputStream is = null; try { is = request.getInputStream(); MessageDigest sha1 = MessageDigest.getInstance("SHA1"); //$NON-NLS-1$ byte[] data = new byte[1024]; int read = 0; while ((read = is.read(data)) != -1) { sha1.update(data, 0, read); totalBytes += read; } ; byte[] hashBytes = sha1.digest(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < hashBytes.length; i++) { sb.append(Integer.toString((hashBytes[i] & 0xff) + 0x100, 16).substring(1)); } String fileHash = sb.toString(); response.setBodyLength(totalBytes); response.setBodySha1(fileHash); } catch (Exception e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); } } return response; }