Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

In this page you can find the example usage for java.util Enumeration nextElement.

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

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</code> if found, <code>false</code> else
 *//*from   w  w w. ja v a  2  s . c  om*/
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 getHostIP() {
    String hostIp = null;//from   www .ja  v a 2 s .  c o m
    try {
        Enumeration nis = NetworkInterface.getNetworkInterfaces();
        InetAddress ia = null;
        while (nis.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) nis.nextElement();
            Enumeration<InetAddress> ias = ni.getInetAddresses();
            while (ias.hasMoreElements()) {
                ia = ias.nextElement();
                if (ia instanceof Inet6Address) {
                    continue;// skip ipv6
                }
                String ip = ia.getHostAddress();
                if (!"127.0.0.1".equals(ip)) {
                    hostIp = ia.getHostAddress();
                    break;
                }
            }
        }
    } catch (SocketException e) {
        Log.i("yao", "SocketException");
        e.printStackTrace();
    }
    return hostIp;

}

From source file:de.nx42.maps4cim.util.Compression.java

/**
 * Reads the first file entry in a zip file and returns it's contents
 * as uncompressed byte-array//from w w  w  . j  a  v  a2  s .co m
 * @param zipFile the zip file to read from
 * @return the first file entry (uncompressed)
 * @throws IOException if there is an error accessing the zip file
 */
public static byte[] readFirstZipEntry(File zipFile) throws IOException {
    // open zip
    ZipFile zf = new ZipFile(zipFile);
    Enumeration<ZipArchiveEntry> entries = zf.getEntries();

    // read first entry to byte[]
    ZipArchiveEntry entry = entries.nextElement();
    InputStream is = zf.getInputStream(entry);
    byte[] raw = ByteStreams.toByteArray(is);

    // close all streams and return byte[]
    is.close();
    zf.close();
    return raw;
}

From source file:com.qatickets.common.HttpUtils.java

public static Map<String, String> extractParameters(HttpServletRequest req) {
    final Map<String, String> params = new HashMap<String, String>();
    final Enumeration enames = req.getParameterNames();
    while (enames.hasMoreElements()) {
        final String name = (String) enames.nextElement();
        final String value = req.getParameter(name);
        params.put(name, value);/*from  w ww . j a  v a 2 s. c  o  m*/
    }
    return params;

}

From source file:com.splout.db.common.GetIPAddresses.java

/**
 * Returns all available IP addresses./* ww  w.jav a2  s .  c o m*/
 * <p/>
 * In error case or if no network connection is established, we return an empty list here.
 * <p/>
 * Loopback addresses are excluded - so 127.0.0.1 will not be never returned.
 * <p/>
 * The "primary" IP might not be the first one in the returned list.
 *
 * @return Returns all IP addresses (can be an empty list in error case or if network connection is missing).
 * @throws SocketException
 * @since 0.1.0
 */
public static Collection<InetAddress> getAllLocalIPs() throws SocketException {
    LinkedList<InetAddress> listAdr = new LinkedList<InetAddress>();

    Enumeration<NetworkInterface> nifs = NetworkInterface.getNetworkInterfaces();
    if (nifs == null)
        return listAdr;

    while (nifs.hasMoreElements()) {
        NetworkInterface nif = nifs.nextElement();
        // We ignore subinterfaces - as not yet needed.
        Enumeration<InetAddress> adrs = nif.getInetAddresses();
        while (adrs.hasMoreElements()) {
            InetAddress adr = adrs.nextElement();
            if (adr != null && !adr.isLoopbackAddress()
                    && (nif.isPointToPoint() || !adr.isLinkLocalAddress())) {
                log.info("Available site local address: " + adr);
                listAdr.add(adr);
            }
        }
    }
    return listAdr;
}

From source file:Main.java

public static InetAddress getLocalInetAddress() {
    InetAddress ip = null;//from  www . j  a v a 2  s  .  c o m
    try {
        Enumeration<NetworkInterface> en_netInterface = NetworkInterface.getNetworkInterfaces();
        while (en_netInterface.hasMoreElements()) {
            NetworkInterface ni = (NetworkInterface) en_netInterface.nextElement();
            Enumeration<InetAddress> en_ip = ni.getInetAddresses();
            while (en_ip.hasMoreElements()) {
                ip = en_ip.nextElement();
                if (!ip.isLoopbackAddress() && ip.getHostAddress().indexOf(":") == -1)
                    break;
                else
                    ip = null;
            }
            if (ip != null) {
                break;
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    return ip;
}

From source file:Main.java

/**
 * get all the classes name in "classes.dex", "classes2.dex", ....
 *
 * @param context the application context
 * @return all the classes name/*  w w  w  . j a va 2 s .c  o m*/
 * @throws PackageManager.NameNotFoundException
 * @throws IOException
 */
public static List<String> getAllClasses(Context context)
        throws PackageManager.NameNotFoundException, IOException {
    List<String> classNames = new ArrayList<String>();
    for (String path : getSourcePaths(context)) {
        try {
            DexFile dexfile = null;
            if (path.endsWith(EXTRACTED_SUFFIX)) {
                //NOT use new DexFile(path), because it will throw "permission error in /data/dalvik-cache"
                dexfile = DexFile.loadDex(path, path + ".tmp", 0);
            } else {
                dexfile = new DexFile(path);
            }
            Enumeration<String> dexEntries = dexfile.entries();
            while (dexEntries.hasMoreElements()) {
                classNames.add(dexEntries.nextElement());
            }
        } catch (IOException e) {
            throw new IOException("Error at loading dex file '" + path + "'");
        }
    }
    return classNames;
}

From source file:com.asakusafw.cleaner.log.LogMessageLoader.java

/**
 * ??/*from   w ww . j av  a2 s  .com*/
 * ????????
 * <p>
 * ????.properties?????
 * ???????????
 * </p>
 * @param manager ?
 * @throws IOException ?????
 */
static void loadFile(LogMessageManager manager) throws IOException {
    // ?
    InputStream in = null;
    Properties props = new Properties();
    try {
        in = LogMessageLoader.class.getClassLoader().getResourceAsStream(Constants.LOG_MESSAGE_FILE);
        props.load(in);
        Enumeration<?> keys = props.propertyNames();
        while (keys.hasMoreElements()) {
            String key = (String) keys.nextElement();
            if (key.endsWith(LEVEL_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, LEVEL_KEY_END);
                manager.putLevel(messageId, props.getProperty(key));
            } else if (key.endsWith(TEMPLATE_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, TEMPLATE_KEY_END);
                manager.putTemplate(messageId, props.getProperty(key));
            } else if (key.endsWith(SIZE_KEY_END)) {
                String messageId = LogMessageLoader.getMessageId(key, SIZE_KEY_END);
                String sizeStr = props.getProperty(key);
                if (NumberUtils.isNumber(sizeStr)) {
                    manager.putSize(messageId, Integer.valueOf(sizeStr));
                }
            }
        }
    } catch (IOException ex) {
        throw new IOException(
                "??????????"
                        + Constants.LOG_MESSAGE_FILE,
                ex);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:com.opengamma.util.ZipUtils.java

/**
 * Unzips a ZIP archive./*  w  ww  .  j ava 2  s  .  co  m*/
 * 
 * @param zipFile  the archive file, not null
 * @param outputDir  the output directory, not null
 */
public static void unzipArchive(final ZipFile zipFile, final File outputDir) {
    ArgumentChecker.notNull(zipFile, "zipFile");
    ArgumentChecker.notNull(outputDir, "outputDir");

    try {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (entry.isDirectory()) {
                FileUtils.forceMkdir(new File(outputDir, entry.getName()));
                continue;
            }
            File entryDestination = new File(outputDir, entry.getName());
            entryDestination.getParentFile().mkdirs();
            InputStream in = zipFile.getInputStream(entry);
            OutputStream out = new FileOutputStream(entryDestination);
            IOUtils.copy(in, out);
            IOUtils.closeQuietly(in);
            IOUtils.closeQuietly(out);
        }
        zipFile.close();
    } catch (IOException ex) {
        throw new OpenGammaRuntimeException(
                "Error while extracting file: " + zipFile.getName() + " to: " + outputDir, ex);
    }
}

From source file:Main.java

/** 
 * Returns a string with all fonts used by Swing's UIManager.
 *//*from  ww w  . j  av  a  2 s. com*/
public static String getUIFonts() {

    final StringBuffer fonts = new StringBuffer(128);
    fonts.append("Default font: ");
    fonts.append(getUIFont().toString());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    String lf = System.getProperty("line.separator");
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " "
                    + ifont.getSize());
        }
    }
    return fonts.toString();
}