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:com.jt.dbcp.example.ManualPoolingDataSourceExample.java

public static void printDataSourceStats(DataSource ds) {
    Enumeration<Driver> driver = DriverManager.getDrivers();
    while (driver.hasMoreElements()) {
        Driver d = driver.nextElement();
        System.out.println(d.getClass());
    }//from   ww w .  ja  v a 2 s .c o m
}

From source file:Main.java

public static List<String> getDexEntries() {
    try {/*from   w  w w  .  ja va  2 s. c om*/
        Object app = Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null);
        Object codePath = Class.forName("android.app.Application").getMethod("getPackageCodePath").invoke(app);
        Class<?> dexFileClass = Class.forName("dalvik.system.DexFile");
        Object dexFile = dexFileClass.getConstructor(String.class).newInstance(codePath);
        Enumeration<String> entries = (Enumeration<String>) dexFileClass.getMethod("entries").invoke(dexFile);
        List<String> dexEntries = new LinkedList<>();
        while (entries.hasMoreElements()) {
            String entry = entries.nextElement();
            entry = entry.replace('.', '/') + ".class";
            dexEntries.add(entry);
        }
        dexFileClass.getMethod("close").invoke(dexFile);
        return dexEntries;
    } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
            | NoSuchMethodException | SecurityException | ClassNotFoundException | InstantiationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.ambraproject.wombat.util.ReproxyUtil.java

/**
 * Check whether a request supports reproxying.
 *
 * @param request a request/*from w  w w  .  ja  va2 s . c o m*/
 * @return {@code true} if it supports reproxying
 */
private static boolean supportsReproxy(HttpServletRequest request) {
    Enumeration headers = request.getHeaders(X_PROXY_CAPABILITIES);
    if (headers != null) {
        while (headers.hasMoreElements()) {
            if (REPROXY_FILE.equals(headers.nextElement())) {
                return true;
            }
        }
    }
    return false;
}

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 w ww.  ja  v a 2 s  . c  o m
    }
    return p;
}

From source file:ezbake.deployer.utilities.VersionHelper.java

private static String getVersionFromPomProperties(File artifact) throws IOException {
    List<JarEntry> pomPropertiesFiles = new ArrayList<>();
    String versionNumber = null;//from   ww w .ja v  a  2 s  .com
    try (JarFile jar = new JarFile(artifact)) {
        JarEntry entry;
        Enumeration<JarEntry> entries = jar.entries();
        while (entries.hasMoreElements()) {
            entry = entries.nextElement();
            if (!entry.isDirectory() && entry.getName().endsWith("pom.properties")) {
                pomPropertiesFiles.add(entry);
            }
        }

        if (pomPropertiesFiles.size() == 1) {
            Properties pomProperties = new Properties();
            pomProperties.load(jar.getInputStream(pomPropertiesFiles.get(0)));
            versionNumber = pomProperties.getProperty("version", null);
        } else {
            logger.debug("Found {} pom.properties files. Cannot use that for version",
                    pomPropertiesFiles.size());
        }
    }
    return versionNumber;
}

From source file:Main.java

public static boolean upZipFile(File zipFile, String folderPath) throws ZipException, IOException {
    ZipFile zfile = new ZipFile(zipFile);
    Enumeration<? extends ZipEntry> zList = zfile.entries();
    ZipEntry ze = null;//ww w.  j a va  2 s .com
    byte[] buf = new byte[1024];
    while (zList.hasMoreElements()) {
        ze = (ZipEntry) zList.nextElement();
        if (ze.isDirectory()) {
            continue;
        }
        Log.d(TAG, "ze.getName() = " + ze.getName());
        OutputStream os = new BufferedOutputStream(
                new FileOutputStream(getRealFileName(folderPath, ze.getName())));
        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();
    }
    zfile.close();
    return true;
}

From source file:com.netsteadfast.greenstep.util.HostUtils.java

public static String getHostAddress() {
    String hostAddress = "";
    try {//from   w ww  .  j  av a 2s  .c o  m
        Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
        for (; nics.hasMoreElements() && "".equals(hostAddress);) {
            NetworkInterface interfece = nics.nextElement();
            if (interfece.getName().toLowerCase().startsWith("lo")) {
                continue;
            }
            Enumeration<InetAddress> addrs = interfece.getInetAddresses();
            for (; addrs.hasMoreElements() && "".equals(hostAddress);) {
                InetAddress addr = addrs.nextElement();
                if (addr.getHostAddress().indexOf(":") > -1) {
                    continue;
                }
                hostAddress = addr.getHostAddress();
            }
        }
    } catch (SocketException e) {
        e.printStackTrace();
    }
    if (StringUtils.isBlank(hostAddress)) {
        hostAddress = "127.0.0.1";
    }
    return hostAddress;
}

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   ww w  .  ja  v a  2 s.  c om*/
            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:jp.co.golorp.emarf.sql.DataSources.java

/**
 * ?//ww  w . j  a v a2  s . c o  m
 *
 * @return DataSource
 */
public static DataSource get() {

    if (ds != null) {
        return ds;
    }

    /*
     * JNDI??
     */

    String name = BUNDLE.getString(DATA_SOURCE_NAME);
    try {
        Context context = new InitialContext();
        ds = (DataSource) context.lookup(name);
        return ds;
    } catch (NamingException e) {
        LOG.warn(e.getMessage());
    }

    /*
     * DBCP??
     */

    Properties properties = new Properties();
    Enumeration<String> keys = BUNDLE.getKeys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        String value = BUNDLE.getString(key);
        properties.put(key, value);
        // if (value.contains("mysql")) {
        // DataSources.isMySQL = true;
        // } else if (value.contains("oracle")) {
        // DataSources.isOracle = true;
        // }
    }

    try {
        ds = BasicDataSourceFactory.createDataSource(properties);
        return ds;
    } catch (Exception e) {
        throw new SystemError(e);
    }
}

From source file:Main.java

public static void unzipEPub(String inputZip, String destinationDirectory) throws IOException {
    int BUFFER = 2048;
    List zipFiles = new ArrayList();
    File sourceZipFile = new File(inputZip);
    File unzipDestinationDirectory = new File(destinationDirectory);
    unzipDestinationDirectory.mkdir();/*w  w w  . ja va 2s  . c o  m*/

    ZipFile zipFile;
    zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ);
    Enumeration zipFileEntries = zipFile.entries();

    // Process each entry
    while (zipFileEntries.hasMoreElements()) {

        ZipEntry entry = (ZipEntry) zipFileEntries.nextElement();
        String currentEntry = entry.getName();
        File destFile = new File(unzipDestinationDirectory, currentEntry);

        if (currentEntry.endsWith(".zip")) {
            zipFiles.add(destFile.getAbsolutePath());
        }

        File destinationParent = destFile.getParentFile();
        destinationParent.mkdirs();

        if (!entry.isDirectory()) {
            BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry));
            int currentByte;
            // buffer for writing file
            byte data[] = new byte[BUFFER];

            FileOutputStream fos = new FileOutputStream(destFile);
            BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);

            while ((currentByte = is.read(data, 0, BUFFER)) != -1) {
                dest.write(data, 0, currentByte);
            }
            dest.flush();
            dest.close();
            is.close();

        }

    }
    zipFile.close();

    for (Iterator iter = zipFiles.iterator(); iter.hasNext();) {
        String zipName = (String) iter.next();
        unzipEPub(zipName,
                destinationDirectory + File.separatorChar + zipName.substring(0, zipName.lastIndexOf(".zip")));
    }
}