List of usage examples for java.util Enumeration nextElement
E nextElement();
From source file:Main.java
public static <T> Iterator<T> iterator(Enumeration<T> enumeration) { return new Iterator<T>() { @Override/*from ww w . j av a 2 s . com*/ public boolean hasNext() { return enumeration.hasMoreElements(); } @Override public T next() { return enumeration.nextElement(); } }; }
From source file:ZipFileUtil.java
/** * @param zipFile//from w w w .j a v a 2s .c o m * @param jiniHomeParentDir */ public static void unzipFileIntoDirectory(ZipFile zipFile, File jiniHomeParentDir) { Enumeration files = zipFile.entries(); File f = null; FileOutputStream fos = null; while (files.hasMoreElements()) { try { ZipEntry entry = (ZipEntry) files.nextElement(); InputStream eis = zipFile.getInputStream(entry); byte[] buffer = new byte[1024]; int bytesRead = 0; f = new File(jiniHomeParentDir.getAbsolutePath() + File.separator + entry.getName()); if (entry.isDirectory()) { f.mkdirs(); continue; } else { f.getParentFile().mkdirs(); f.createNewFile(); } fos = new FileOutputStream(f); while ((bytesRead = eis.read(buffer)) != -1) { fos.write(buffer, 0, bytesRead); } } catch (IOException e) { e.printStackTrace(); continue; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { // ignore } } } } }
From source file:io.reactiverse.vertx.maven.plugin.utils.WebJars.java
/** * Checks whether the given file is a WebJar or not (http://www.webjars.org/documentation). * The check is based on the presence of {@literal META-INF/resources/webjars/} directory in the jar file. * * @param file the file.// ww w . j a v a2 s. c o m * @return {@literal true} if it's a bundle, {@literal false} otherwise. */ public static boolean isWebJar(Log log, File file) { if (file == null) { return false; } Set<String> found = new LinkedHashSet<>(); if (file.isFile() && file.getName().endsWith(".jar")) { try (JarFile jar = new JarFile(file)) { // Fast return if the base structure is not there if (jar.getEntry(WEBJAR_LOCATION) == null) { return false; } Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); Matcher matcher = WEBJAR_REGEX.matcher(entry.getName()); if (matcher.matches()) { found.add(matcher.group(1) + "-" + matcher.group(2)); } } } catch (IOException e) { log.error("Cannot check if the file " + file.getName() + " is a webjar, cannot open it", e); return false; } for (String lib : found) { log.info("Web Library found in " + file.getName() + " : " + lib); } return !found.isEmpty(); } return false; }
From source file:com.predic8.membrane.examples.DistributionExtractingTestcase.java
public static final void unzip(File zip, File target) throws IOException { ZipFile zipFile = new ZipFile(zip); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.isDirectory()) { // Assume directories are stored parents first then children. // This is not robust, just for demonstration purposes. new File(target, entry.getName()).mkdir(); } else {/*from ww w .jav a2s . co m*/ FileOutputStream fos = new FileOutputStream(new File(target, entry.getName())); try { copyInputStream(zipFile.getInputStream(entry), new BufferedOutputStream(fos)); } finally { fos.close(); } } } zipFile.close(); }
From source file:de.langmi.spring.batch.examples.readers.file.zip.ZipMultiResourceItemReader.java
/** * Extract only files from the zip archive. * * @param currentZipFile/*from w w w . j a va 2s. com*/ * @param extractedResources * @throws IOException */ private static void extractFiles(final ZipFile currentZipFile, final List<Resource> extractedResources) throws IOException { Enumeration<? extends ZipEntry> zipEntryEnum = currentZipFile.entries(); while (zipEntryEnum.hasMoreElements()) { ZipEntry zipEntry = zipEntryEnum.nextElement(); LOG.info("extracting:" + zipEntry.getName()); // traverse directories if (!zipEntry.isDirectory()) { // add inputStream extractedResources .add(new InputStreamResource(currentZipFile.getInputStream(zipEntry), zipEntry.getName())); LOG.info("using extracted file:" + zipEntry.getName()); } } }
From source file:org.cloudfoundry.client.lib.SampleProjects.java
private static void unpackZip(ZipFile zipFile, File unpackDir) throws IOException { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); File destination = new File(unpackDir.getAbsolutePath() + "/" + entry.getName()); if (entry.isDirectory()) { destination.mkdirs();/*from www .j a v a 2 s . c om*/ } else { destination.getParentFile().mkdirs(); FileCopyUtils.copy(zipFile.getInputStream(entry), new FileOutputStream(destination)); } if (entry.getTime() != -1) { destination.setLastModified(entry.getTime()); } } }
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;//w ww . j a v a 2s. co 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:hudson.plugins.codeviation.JavaFileIterableView.java
public static void updateGraphType(StaplerRequest req, StaplerResponse rsp) { chartType = req.getParameter(CHART_TYPE_PARAM); Enumeration en = req.getParameterNames(); while (en.hasMoreElements()) { System.out.println(en.nextElement()); }/*from w w w . j av a 2s . c o m*/ if (chartType != null) { rsp.addCookie(new Cookie(CHART_TYPE_PARAM, chartType)); } }
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 ww w . j a va2 s.co m * * 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.servoy.j2db.util.SecuritySupport.java
public static Key getCryptKey(Settings settings) throws Exception { initKeyStoreAndPassphrase(settings); Enumeration e = keyStore.aliases(); while (e.hasMoreElements()) { String alias = (String) e.nextElement(); if (keyStore.isKeyEntry(alias)) { return new SecretKeySpec( new DESedeKeySpec(keyStore.getKey(alias, passphrase).getEncoded()).getKey(), "DESede"); }//ww w . j a va 2 s .c om } return null; }