Example usage for java.util Enumeration hasMoreElements

List of usage examples for java.util Enumeration hasMoreElements

Introduction

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

Prototype

boolean hasMoreElements();

Source Link

Document

Tests if this enumeration contains more elements.

Usage

From source file:Main.java

/**
 * Create a Hashtable by pairing the given keys with the given values.
 * Equivalent to python code <code>dict(zip(keys, values))</code>
 *///from ww  w . j  a  va 2s.c o m
public static Hashtable createHashtable(Vector keys, Vector values) {
    Enumeration keyEnum = keys.elements();
    Enumeration valEnum = values.elements();

    Hashtable result = new Hashtable();
    while (keyEnum.hasMoreElements() && valEnum.hasMoreElements())
        result.put(keyEnum.nextElement(), valEnum.nextElement());

    return result;
}

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();/* w w  w . j a  v  a  2 s  . c  om*/
    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:com.daphne.es.maintain.editor.web.controller.utils.CompressUtils.java

@SuppressWarnings("unchecked")
private static void unzipFolder(File uncompressFile, File descPathFile, boolean override) {

    ZipFile zipFile = null;// www. j  a v  a  2 s .c o m
    try {
        zipFile = new ZipFile(uncompressFile, "GBK");

        Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
        while (entries.hasMoreElements()) {
            ZipArchiveEntry zipEntry = entries.nextElement();
            String name = zipEntry.getName();
            name = name.replace("\\", "/");

            File currentFile = new File(descPathFile, name);

            //? 
            if (currentFile.isFile() && currentFile.exists() && !override) {
                continue;
            }

            if (name.endsWith("/")) {
                currentFile.mkdirs();
                continue;
            } else {
                currentFile.getParentFile().mkdirs();
            }

            FileOutputStream fos = null;
            try {
                fos = new FileOutputStream(currentFile);
                InputStream is = zipFile.getInputStream(zipEntry);
                IOUtils.copy(is, fos);
            } finally {
                IOUtils.closeQuietly(fos);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("", e);
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException e) {
            }
        }
    }

}

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());
    }// ww w  .  j a  va  2s  . c  om
}

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;/* w w  w  . j a v  a 2  s . c om*/
    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:azkaban.jobtype.connectors.teradata.TeraDataWalletInitializer.java

/**
 * As of TDCH 1.4.1, integration with Teradata wallet only works with hadoop jar command line command.
 * This is mainly because TDCH depends on the behavior of hadoop jar command line which extracts jar file
 * into hadoop tmp folder.//from w w  w  .  ja  v a  2 s.c  om
 *
 * This method will extract tdchJarfile and place it into temporary folder, and also add jvm shutdown hook
 * to delete the directory when JVM shuts down.
 * @param tdchJarFile TDCH jar file.
 */
public static void initialize(File tmpDir, File tdchJarFile) {
    synchronized (TeraDataWalletInitializer.class) {
        if (tdchJarExtractedDir != null) {
            return;
        }

        if (tdchJarFile == null) {
            throw new IllegalArgumentException("TDCH jar file cannot be null.");
        }
        if (!tdchJarFile.exists()) {
            throw new IllegalArgumentException(
                    "TDCH jar file does not exist. " + tdchJarFile.getAbsolutePath());
        }
        try {
            //Extract TDCH jar.
            File unJarDir = createUnjarDir(
                    new File(tmpDir.getAbsolutePath() + File.separator + UNJAR_DIR_NAME));
            JarFile jar = new JarFile(tdchJarFile);
            Enumeration<JarEntry> enumEntries = jar.entries();

            while (enumEntries.hasMoreElements()) {
                JarEntry srcFile = enumEntries.nextElement();
                File destFile = new File(unJarDir + File.separator + srcFile.getName());
                if (srcFile.isDirectory()) { // if its a directory, create it
                    destFile.mkdir();
                    continue;
                }

                InputStream is = jar.getInputStream(srcFile);
                BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(destFile));
                IOUtils.copy(is, os);
                close(os);
                close(is);
            }
            jar.close();
            tdchJarExtractedDir = unJarDir;
        } catch (IOException e) {
            throw new RuntimeException("Failed while extracting TDCH jar file.", e);
        }
    }
    logger.info("TDCH jar has been extracted into directory: " + tdchJarExtractedDir.getAbsolutePath());
}

From source file:com.icesoft.net.messaging.jms.AbstractJMSConnection.java

protected static String toString(final javax.jms.Message message) {
    StringBuffer _messageString = new StringBuffer();
    try {//  w w w . ja  v a  2 s . c om
        Enumeration _propertyNames = message.getPropertyNames();
        while (_propertyNames.hasMoreElements()) {
            String _propertyName = (String) _propertyNames.nextElement();
            _messageString.append(_propertyName);
            _messageString.append(": ");
            _messageString.append(message.getObjectProperty(_propertyName));
            _messageString.append("\r\n");
        }
        _messageString.append("\r\n");
        if (message instanceof javax.jms.ObjectMessage) {
            _messageString.append(((javax.jms.ObjectMessage) message).getObject());
        } else if (message instanceof javax.jms.TextMessage) {
            _messageString.append(((javax.jms.TextMessage) message).getText());
        }
        _messageString.append("\r\n");
    } catch (JMSException exception) {
        // do nothing (this is just a toString() method)
    }
    return _messageString.toString();
}

From source file:com.android.tradefed.util.ZipUtil2.java

/**
 * Utility method to extract entire contents of zip file into given directory
 *
 * @param zipFile the {@link ZipFile} to extract
 * @param destDir the local dir to extract file to
 * @throws IOException if failed to extract file
 *///  w w w . j  a va2s  .  c om
public static void extractZip(ZipFile zipFile, File destDir) throws IOException {
    Enumeration<? extends ZipArchiveEntry> entries = zipFile.getEntries();
    while (entries.hasMoreElements()) {
        ZipArchiveEntry entry = entries.nextElement();
        File childFile = new File(destDir, entry.getName());
        childFile.getParentFile().mkdirs();
        if (entry.isDirectory()) {
            childFile.mkdirs();
            applyUnixModeIfNecessary(entry, childFile);
            continue;
        } else {
            FileUtil.writeToFile(zipFile.getInputStream(entry), childFile);
            applyUnixModeIfNecessary(entry, childFile);
        }
    }
}

From source file:com.willwinder.universalgcodesender.i18n.Localization.java

private static int getKeyCount(ResourceBundle b) {
    Enumeration<String> keyEnum = b.getKeys();

    int ret = 0;/*from w  w  w.j a v a 2  s .  co m*/
    while (keyEnum.hasMoreElements()) {
        keyEnum.nextElement();
        ret++;
    }

    return ret;
}

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

private static String getVersionFromPomProperties(File artifact) throws IOException {
    List<JarEntry> pomPropertiesFiles = new ArrayList<>();
    String versionNumber = null;/* www .  jav  a2 s .  co m*/
    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;
}