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.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java

public static void unzip(File zip, File dest, Charset charset) throws IOException {
    Path destPath = dest.toPath();
    try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Path entryPath = destPath.resolve(entry.getName());
            if (!entryPath.normalize().startsWith(dest.toPath()))
                throw new IOException("Zip entry contained path traversal");
            if (entry.isDirectory()) {
                Files.createDirectories(entryPath);
            } else {
                Files.createDirectories(entryPath.getParent());
                try (InputStream in = zipFile.getInputStream(entry)) {
                    try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
                        IOUtils.copy(in, out);
                    }/* w  w  w. j  a  va2  s .  com*/
                }
            }
        }
    }
}

From source file:com.opoopress.maven.plugins.plugin.zip.ZipUtils.java

public static void unzipFileToDirectory(File file, File destDir, boolean keepTimestamp) throws IOException {
    // create output directory if it doesn't exist
    if (!destDir.exists())
        destDir.mkdirs();//  ww w.  j av a 2s  .  c o  m

    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (entry.isDirectory()) {
            new File(destDir, entry.getName()).mkdirs();
            continue;
        }

        InputStream inputStream = zipFile.getInputStream(entry);
        File destFile = new File(destDir, entry.getName());

        System.out.println("Unzipping to " + destFile.getAbsolutePath());
        FileUtils.copyInputStreamToFile(inputStream, destFile);
        IOUtils.closeQuietly(inputStream);

        if (keepTimestamp) {
            long time = entry.getTime();
            if (time > 0) {
                destFile.setLastModified(time);
            }
        }
    }

    zipFile.close();
}

From source file:Main.java

public static String getChannel(Context context) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    ZipFile zipfile = null;//  ww  w .ja v a2  s  . c  o m
    String ret = null;
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith(FOLDER_NAME) && entryName.contains(CHANNEL_SCHEME)) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    try {
        if (ret != null) {
            String[] split = ret.split(CHANNEL_SCHEME_SPIT);
            if (split.length >= 2) {
                return ret.substring(split[0].length() + 1);
            }
        }
    } catch (Exception e) {

    }

    return null;
}

From source file:Main.java

/**
 * Dictionary does not have an equals.//from   w  w  w . j  a  v a  2 s  . c  o m
 * Please use  Map.equals().
 *
 * <p>Follows the equals contract of Java 2's Map.</p>
 * @param d1 the first directory.
 * @param d2 the second directory.
 * @return true if the directories are equal.
 * @since Ant 1.5
 * @deprecated since 1.6.x.
 */
public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) {
    if (d1 == d2) {
        return true;
    }

    if (d1 == null || d2 == null) {
        return false;
    }

    if (d1.size() != d2.size()) {
        return false;
    }

    Enumeration<?> e1 = d1.keys();
    while (e1.hasMoreElements()) {
        Object key = e1.nextElement();
        Object value1 = d1.get(key);
        Object value2 = d2.get(key);
        if (value2 == null || !value1.equals(value2)) {
            return false;
        }
    }

    // don't need the opposite check as the Dictionaries have the
    // same size, so we've also covered all keys of d2 already.

    return true;
}

From source file:org.tsm.concharto.auth.AuthHelper.java

@SuppressWarnings("unchecked")
public static void clearCredentials(HttpServletRequest request, HttpServletResponse response) {
    //clear out the session
    Enumeration attrNames = request.getSession().getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String name = (String) attrNames.nextElement();
        WebUtils.setSessionAttribute(request, name, null);
        //free all session data
        request.getSession().invalidate();
    }/*  ww  w.  j a  v a2  s. com*/
    //clear the remember me cookies
    AuthHelper.setCookie(response, AuthHelper.COOKIE_REMEMBER_ME, 0, "");
    AuthHelper.setCookie(response, AuthHelper.COOKIE_REMEMBER_ME_USERNAME, 0, "");

}

From source file:com.krawler.portal.util.SystemEnv.java

public static void setProperties(Properties props) {
    Properties envProps = getProperties();

    Enumeration<String> enu = (Enumeration<String>) envProps.propertyNames();

    while (enu.hasMoreElements()) {
        String key = enu.nextElement();

        props.setProperty("env." + key, (String) envProps.get(key));
    }/*from  w w w  .j  ava 2s .  co  m*/
}

From source file:Main.java

public static String getLocalIpAddress(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = wifiManager.getConnectionInfo();
    if (wifiInfo != null && wifiInfo.getIpAddress() != 0) {
        return android.text.format.Formatter.formatIpAddress(wifiInfo.getIpAddress());
    } else {/*from   w  w  w. ja  v a2 s .c  o  m*/
        try {
            Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
            while (en.hasMoreElements()) {
                NetworkInterface intf = en.nextElement();
                Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses();
                while (enumIpAddr.hasMoreElements()) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress() && inetAddress.getHostAddress().indexOf(":") == -1) {
                        String ipAddress = inetAddress.getHostAddress();
                        if (!TextUtils.isEmpty(ipAddress) && !ipAddress.contains(":")) {
                            return ipAddress;
                        }
                    }
                }
            }
        } catch (SocketException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:net.bpelunit.util.ZipUtil.java

public static void unzipFile(File zip, File dir) throws IOException {
    InputStream in = null;//  w  ww.  ja v a  2s. com
    OutputStream out = null;
    ZipFile zipFile = new ZipFile(zip);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.getName().endsWith("/")) {
            File unzippedFile = new File(dir, entry.getName());
            try {
                in = zipFile.getInputStream(entry);
                unzippedFile.getParentFile().mkdirs();

                out = new FileOutputStream(unzippedFile);

                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(out);
            }
        }
    }
}

From source file:com.athomas.androidkickstartr.util.ResourcesUtils.java

private static void copyResourcesToFromJar(File target, URL url) throws IOException {
    JarURLConnection connection = (JarURLConnection) url.openConnection();
    JarFile jarFile = connection.getJarFile();

    Enumeration<JarEntry> entries = jarFile.entries();

    while (entries.hasMoreElements()) {
        JarEntry jarEntry = entries.nextElement();
        InputStream is = jarFile.getInputStream(jarEntry);
        String entryPath = jarEntry.getName();

        File file = null;//from w  w w  .j av a  2s  . com
        String dirs = "";
        if (entryPath.contains("/")) {
            int lastIndexOf = entryPath.lastIndexOf("/");
            dirs = (String) entryPath.subSequence(0, lastIndexOf + 1);
        }

        File parent = new File(target, dirs);
        parent.mkdirs();

        if (!jarEntry.isDirectory()) {
            String[] splitedPath = entryPath.split("/");
            String fileName = splitedPath[splitedPath.length - 1];
            file = new File(parent, fileName);
            FileUtils.copyInputStreamToFile(is, file);
        }
    }
}

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

public static void uncompress(File file, File dest) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        File entryDestination = new File(dest, entry.getName());
        entryDestination.getParentFile().mkdirs();
        InputStream in = zipFile.getInputStream(entry);
        OutputStream out = new FileOutputStream(entryDestination);
        IOUtils.copy(in, out);//from   ww  w.  j ava 2 s . c  o m
        in.close();
        out.close();
    }
}