List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:com.freedomotic.util.Unzip.java
/** * * @param zipFile/*from www .ja va 2s. c o m*/ * @throws ZipException * @throws IOException */ public static void unzip(String zipFile) throws IOException { if (StringUtils.isEmpty(zipFile)) { LOG.error("File path not provided, no unzipping performed"); return; } File file = new File(zipFile); if (!file.exists()) { LOG.error("File not existing, no unzipping performed"); return; } try (ZipFile zip = new ZipFile(file);) { String newPath = zipFile.substring(0, zipFile.length() - 4); //simulates the unzip here feature newPath = newPath.substring(0, newPath.lastIndexOf(File.separator)); Enumeration<? extends ZipEntry> zipFileEntries = zip.entries(); // Process each entry while (zipFileEntries.hasMoreElements()) { // grab a zip file entry ZipEntry entry = zipFileEntries.nextElement(); String currentEntry = entry.getName(); File destFile = new File(newPath, currentEntry); File destinationParent = destFile.getParentFile(); // create the parent directory structure if needed destinationParent.mkdirs(); if (!entry.isDirectory()) { try (BufferedInputStream is = new BufferedInputStream(zip.getInputStream(entry)); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);) { int currentByte; // establish buffer for writing file byte[] data = new byte[BUFFER]; // read and write until last byte is encountered while ((currentByte = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, currentByte); } } catch (IOException ex) { LOG.error(Freedomotic.getStackTraceInfo(ex)); } } if (currentEntry.endsWith(".zip")) { // found a zip file, try to open unzip(destFile.getAbsolutePath()); } } } }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * @param request// w w w.j av a 2s.c om */ public static void printRequestHeaders(final HttpServletRequest request) { log.debug("Request headers:"); final Enumeration<?> headerNames = request.getHeaderNames(); while (headerNames.hasMoreElements()) { final String name = (String) headerNames.nextElement(); log.debug(name + " = " + request.getHeader(name)); } }
From source file:gov.nih.nci.cabig.ctms.web.WebTools.java
@SuppressWarnings({ "unchecked" }) public static SortedMap<String, String[]> headersToMap(final HttpServletRequest request) { return namedAttributesToMap(request.getHeaderNames(), new AttributeAccessor<String[]>() { @SuppressWarnings({ "unchecked" }) public String[] getAttribute(String headerName) { Enumeration<String> values = request.getHeaders(headerName); List<String> valList = new ArrayList<String>(); while (values.hasMoreElements()) { valList.add(values.nextElement()); }/*from www . j av a 2 s . c o m*/ return valList.toArray(new String[valList.size()]); } }); }
From source file:de.lazyzero.kkMulticopterFlashTool.utils.Zip.java
public static void unzip2folder(File zipFile, File toFolder) throws FileExistsException { if (!toFolder.exists()) { toFolder.mkdirs();// ww w . j a v a 2 s .c o m } else if (toFolder.isFile()) { throw new FileExistsException(toFolder.getName()); } try { ZipEntry entry; @SuppressWarnings("resource") ZipFile zipfile = new ZipFile(zipFile); Enumeration<? extends ZipEntry> e = zipfile.entries(); while (e.hasMoreElements()) { entry = e.nextElement(); // String newDir; // if (entry.getName().indexOf("/") == -1) { // newDir = zipFile.getName().substring(0, zipFile.getName().indexOf(".")); // } else { // newDir = entry.getName().substring(0, entry.getName().indexOf("/")); // } // String folder = toFolder + (File.separatorChar+"") + newDir; // System.out.println(folder); // if ((new File(folder).mkdir())) { // System.out.println("Done."); // } System.out.println("Extracting: " + entry); if (entry.isDirectory()) { new File(toFolder + (File.separatorChar + "") + entry.getName()).mkdir(); } else { BufferedInputStream is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[2048]; String fileName = toFolder + (File.separatorChar + "") + entry.getName(); FileOutputStream fos = new FileOutputStream(fileName); BufferedOutputStream dest = new BufferedOutputStream(fos, 2048); while ((count = is.read(data, 0, 2048)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); System.out.println("extracted to: " + fileName); } } } catch (ZipException e1) { zipFile.delete(); e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } finally { } }
From source file:net.kungfoo.grizzly.proxy.impl.ProxyAdapter.java
private static HttpRequest convert(String method, String uri, Request request) { HttpRequest req;/*from w ww .j a va2 s.co m*/ final int len = request.getContentLength(); if (len > 0) { req = new BasicHttpEntityEnclosingRequest(method, uri); final BasicHttpEntity httpEntity = new BasicHttpEntity(); httpEntity.setContentLength(len); // httpEntity.setContent(((InternalInputBuffer) request.getInputBuffer()).getInputStream()); ((BasicHttpEntityEnclosingRequest) req).setEntity(httpEntity); } else { req = new BasicHttpRequest(method, uri); } final MimeHeaders mimeHeaders = request.getMimeHeaders(); final Enumeration names = mimeHeaders.names(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); req.addHeader(name, mimeHeaders.getHeader(name)); } return req; }
From source file:com.fjn.helper.common.io.file.zip.zip.ZipArchiveHelper.java
/** * zip/* w w w. j a v a 2 s. co m*/ * * @param zipFile * @param targetDirPath */ public static void upZip(File zipFile, String targetDirPath, String filenameEncoding) { if (!zipFile.exists()) return; File targetDir = FileUtil.ensureDirExists(targetDirPath); ZipFile zipfile = null; try { zipfile = new ZipFile(zipFile, filenameEncoding); ZipArchiveEntry zipEntry = null; InputStream fileIn = null; Enumeration<? extends ZipArchiveEntry> enumer = zipfile.getEntries();// zipfile.entries(); while (enumer.hasMoreElements()) { zipEntry = enumer.nextElement(); if (zipEntry.isDirectory()) { FileUtil.ensureChildDirExists(targetDir, zipEntry.getName()); } else { logger.info("unzip file" + zipEntry.getName()); fileIn = zipfile.getInputStream(zipEntry); File file2 = FileUtil.ensureFileExists(targetDirPath, zipEntry.getName()); FileUtil.copyInputStreamToFile(fileIn, file2); fileIn.close(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (zipfile != null) { try { zipfile.close(); } catch (IOException e) { // ignore it } } } logger.info("?"); }
From source file:ie.deri.unlp.javaservices.topicextraction.topicextractor.gate.TopicExtractorGate.java
/** * /*from w ww.j a v a 2s. co m*/ * Extract a directory in a JAR on the classpath to an output folder. * * Note: User's responsibility to ensure that the files are actually in a JAR. * * @param classInJar A class in the JAR file which is on the classpath * @param resourceDirectory Path to resource directory in JAR * @param outputDirectory Directory to write to * @return String containing the path to the outputDirectory * @throws IOException */ private static String extractDirectoryFromClasspathJAR(Class<?> classInJar, String resourceDirectory, String outputDirectory) throws IOException { resourceDirectory = StringUtils.strip(resourceDirectory, "\\/") + File.separator; URL jar = classInJar.getProtectionDomain().getCodeSource().getLocation(); JarFile jarFile = new JarFile(new File(jar.getFile())); byte[] buf = new byte[1024]; Enumeration<JarEntry> jarEntries = jarFile.entries(); while (jarEntries.hasMoreElements()) { JarEntry jarEntry = jarEntries.nextElement(); if (jarEntry.isDirectory() || !jarEntry.getName().startsWith(resourceDirectory)) { continue; } String outputFileName = FilenameUtils.concat(outputDirectory, jarEntry.getName()); //Create directories if they don't exist new File(FilenameUtils.getFullPath(outputFileName)).mkdirs(); //Write file FileOutputStream fileOutputStream = new FileOutputStream(outputFileName); int n; InputStream is = jarFile.getInputStream(jarEntry); while ((n = is.read(buf, 0, 1024)) > -1) { fileOutputStream.write(buf, 0, n); } is.close(); fileOutputStream.close(); } jarFile.close(); String fullPath = FilenameUtils.concat(outputDirectory, resourceDirectory); return fullPath; }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the init parameters for a {@link javax.servlet.ServletConfig} object as a Map, preserving the order in which they are exposed * by the {@link javax.servlet.ServletConfig} object. *///from w ww . ja v a2 s . c o m public static LinkedHashMap<String, String> initParametersToMap(ServletConfig config) { LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>(); Enumeration parameterNames = config.getInitParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); initParameters.put(parameterName, config.getInitParameter(parameterName)); } return initParameters; }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the init parameters for a {@link javax.servlet.FilterConfig} object as a Map, preserving the order in which they are exposed * by the {@link javax.servlet.FilterConfig} object. *//*from w w w . jav a 2 s. co m*/ public static LinkedHashMap<String, String> initParametersToMap(FilterConfig config) { LinkedHashMap<String, String> initParameters = new LinkedHashMap<String, String>(); Enumeration parameterNames = config.getInitParameterNames(); while (parameterNames.hasMoreElements()) { String parameterName = (String) parameterNames.nextElement(); initParameters.put(parameterName, config.getInitParameter(parameterName)); } return initParameters; }
From source file:Main.java
public static String GetIPAdresses_JAVA() { String allIPAdresses = ""; Enumeration<NetworkInterface> e = null; try {//from w w w. ja v a 2 s.c o m e = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e1) { e1.printStackTrace(); } if (e != null) { while (e.hasMoreElements()) { NetworkInterface n = (NetworkInterface) e.nextElement(); Enumeration<InetAddress> ee = n.getInetAddresses(); while (ee.hasMoreElements()) { InetAddress i = (InetAddress) ee.nextElement(); allIPAdresses += (i.getHostAddress() + "\n"); } } } return allIPAdresses; }