List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.onehippo.repository.xml.ExportImportPackageTest.java
private Map<String, File> unzipFileTo(File file, File targetBaseDir) throws IOException { Map<String, File> entryFilesMap = new HashMap<String, File>(); ZipFile zipFile = new ZipFile(file); try {//from www .j a va 2s . co m for (ZipEntry zipEntry : Collections.list(zipFile.entries())) { InputStream in = null; OutputStream out = null; File targetFile = null; try { in = zipFile.getInputStream(zipEntry); targetFile = new File(targetBaseDir, zipEntry.getName()); out = new FileOutputStream(targetFile); IOUtils.copy(in, out); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } entryFilesMap.put(zipEntry.getName(), targetFile); } } finally { zipFile.close(); } return entryFilesMap; }
From source file:com.icesoft.faces.webapp.http.servlet.ServletEnvironmentRequest.java
public ServletEnvironmentRequest(Object request, HttpSession session, Authorization authorization) { HttpServletRequest initialRequest = (HttpServletRequest) request; this.session = session; this.authorization = authorization; //Copy common data authType = initialRequest.getAuthType(); contextPath = initialRequest.getContextPath(); remoteUser = initialRequest.getRemoteUser(); userPrincipal = initialRequest.getUserPrincipal(); requestedSessionId = initialRequest.getRequestedSessionId(); requestedSessionIdValid = initialRequest.isRequestedSessionIdValid(); attributes = new HashMap(); Enumeration attributeNames = initialRequest.getAttributeNames(); while (attributeNames.hasMoreElements()) { String name = (String) attributeNames.nextElement(); Object attribute = initialRequest.getAttribute(name); if ((null != name) && (null != attribute)) { attributes.put(name, attribute); }//from w w w. jav a 2s .c o m } // Warning: For some reason, the various javax.include.* attributes are // not available via the getAttributeNames() call. This may be limited // to a Liferay issue but when the MainPortlet dispatches the call to // the MainServlet, all of the javax.include.* attributes can be // retrieved using this.request.getAttribute() but they do NOT appear in // the Enumeration of names returned by getAttributeNames(). So here // we manually add them to our map to ensure we can find them later. String[] incAttrKeys = Constants.INC_CONSTANTS; for (int index = 0; index < incAttrKeys.length; index++) { String incAttrKey = incAttrKeys[index]; Object incAttrVal = initialRequest.getAttribute(incAttrKey); if (incAttrVal != null) { attributes.put(incAttrKey, initialRequest.getAttribute(incAttrKey)); } } headers = new HashMap(); Enumeration headerNames = initialRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); Enumeration values = initialRequest.getHeaders(name); headers.put(name, Collections.list(values)); } parameters = new HashMap(); Enumeration parameterNames = initialRequest.getParameterNames(); while (parameterNames.hasMoreElements()) { String name = (String) parameterNames.nextElement(); parameters.put(name, initialRequest.getParameterValues(name)); } scheme = initialRequest.getScheme(); serverName = initialRequest.getServerName(); serverPort = initialRequest.getServerPort(); secure = initialRequest.isSecure(); //Copy servlet specific data cookies = initialRequest.getCookies(); method = initialRequest.getMethod(); pathInfo = initialRequest.getPathInfo(); pathTranslated = initialRequest.getPathTranslated(); queryString = initialRequest.getQueryString(); requestURI = initialRequest.getRequestURI(); try { requestURL = initialRequest.getRequestURL(); } catch (NullPointerException e) { //TODO remove this catch block when GlassFish bug is addressed if (log.isErrorEnabled()) { log.error("Null Protocol Scheme in request", e); } HttpServletRequest req = initialRequest; requestURL = new StringBuffer( "http://" + req.getServerName() + ":" + req.getServerPort() + req.getRequestURI()); } servletPath = initialRequest.getServletPath(); servletSession = initialRequest.getSession(); isRequestedSessionIdFromCookie = initialRequest.isRequestedSessionIdFromCookie(); isRequestedSessionIdFromURL = initialRequest.isRequestedSessionIdFromURL(); characterEncoding = initialRequest.getCharacterEncoding(); contentLength = initialRequest.getContentLength(); contentType = initialRequest.getContentType(); protocol = initialRequest.getProtocol(); remoteAddr = initialRequest.getRemoteAddr(); remoteHost = initialRequest.getRemoteHost(); initializeServlet2point4Properties(initialRequest); }
From source file:net.ontopia.utils.ResourcesDirectoryReader.java
private List<URL> getResourceDirectories() { try {// w w w .j a va2 s. c o m Enumeration<URL> directories = classLoader.getResources(directoryPath); return Collections.list(directories); } catch (IOException e) { return Collections.emptyList(); } }
From source file:net.straylightlabs.archivo.controller.TelemetryController.java
private static List<String> getNetworkInterfaces() { List<String> nics = new ArrayList<>(); try {/* w w w . j a v a2s. com*/ for (NetworkInterface nic : Collections.list(NetworkInterface.getNetworkInterfaces())) { if (nic.isUp()) nics.add(String.format( "name='%s' isLoopback=%b isP2P=%b isVirtual=%b multicast=%b addresses=[%s]\n", nic.getDisplayName(), nic.isLoopback(), nic.isPointToPoint(), nic.isVirtual(), nic.supportsMulticast(), getAddressesAsString(nic))); } } catch (SocketException e) { logger.error("Error fetching network interface list: ", e); } return nics; }
From source file:org.apache.sling.scripting.sightly.render.AbstractRuntimeObjectModel.java
@SuppressWarnings("unchecked") protected Collection<Object> obtainCollection(Object obj) { if (obj == null) { return Collections.emptyList(); }/* w w w . j a v a 2 s. c o m*/ if (obj instanceof Object[]) { return Arrays.asList((Object[]) obj); } if (obj instanceof Collection) { return (Collection<Object>) obj; } if (obj instanceof Map) { return ((Map) obj).keySet(); } if (obj instanceof Record) { return ((Record) obj).getPropertyNames(); } if (obj instanceof Enumeration) { return Collections.list((Enumeration<Object>) obj); } if (obj instanceof Iterator) { return fromIterator((Iterator<Object>) obj); } if (obj instanceof Iterable) { Iterable iterable = (Iterable) obj; return fromIterator(iterable.iterator()); } if (obj instanceof String || obj instanceof Number) { Collection list = new ArrayList(); list.add(obj); return list; } return Collections.emptyList(); }
From source file:by.stub.yaml.stubs.StubRequest.java
public static StubRequest createFromHttpServletRequest(final HttpServletRequest request) throws IOException { final StubRequest assertionRequest = StubRequest.newStubRequest(request.getPathInfo(), HandlerUtils.extractPostRequestBody(request, "stubs")); assertionRequest.addMethod(request.getMethod()); final Enumeration<String> headerNamesEnumeration = request.getHeaderNames(); final List<String> headerNames = ObjectUtils.isNotNull(headerNamesEnumeration) ? Collections.list(request.getHeaderNames()) : new LinkedList<String>(); for (final String headerName : headerNames) { final String headerValue = request.getHeader(headerName); assertionRequest.getHeaders().put(StringUtils.toLower(headerName), headerValue); }//w w w . j av a2 s.c o m assertionRequest.getQuery().putAll(CollectionUtils.constructParamMap(request.getQueryString())); ConsoleUtils.logAssertingRequest(assertionRequest); return assertionRequest; }
From source file:org.mule.module.http.functional.listener.HttpListenerConfigFunctionalTestCase.java
private String getNonLocalhostIp() { try {//from w ww. j a va 2s. c o m Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface networkInterface : Collections.list(nets)) { final Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses(); while (inetAddresses.hasMoreElements()) { InetAddress inetAddress = inetAddresses.nextElement(); if (!inetAddress.isLoopbackAddress() && IPADDRESS_PATTERN.matcher(inetAddress.getHostAddress()).find()) { return inetAddress.getHostAddress(); } } } throw new RuntimeException("Could not find network interface different from localhost"); } catch (SocketException e) { throw new RuntimeException(e); } }
From source file:org.pentaho.hadoop.PropertiesConfigurationPropertiesTest.java
@Test public void testElements() { Map<String, Object> sourceMap = new HashMap<>(); sourceMap.put("a", "b"); sourceMap.put("c", "d"); mockToMap(sourceMap);/*from www . ja v a 2 s .com*/ assertEquals(new HashSet<>(sourceMap.values()), new HashSet<>(Collections.list(propertiesConfigurationProperties.elements()))); }
From source file:org.orcid.core.cli.LoadRinggoldData.java
private void processZip() { try (ZipFile zip = new ZipFile(zipFile)) { ZipEntry parentsEntry = null; ZipEntry deletedIdsEntry = null; ZipEntry altNamesEntry = null; for (ZipEntry entry : Collections.list(zip.entries())) { String entryName = entry.getName(); if (entryName.endsWith("_parents.csv")) { LOGGER.info("Found parents file: " + entryName); parentsEntry = entry;/*from w w w. ja v a2s. c o m*/ } if (entryName.endsWith("deleted_ids.csv")) { LOGGER.info("Found deleted ids file: " + entryName); deletedIdsEntry = entry; } if (entryName.endsWith("alt_names.csv")) { LOGGER.info("Found alt names file: " + entryName); altNamesEntry = entry; } } if (parentsEntry != null) { Reader reader = getReader(zip, parentsEntry); if (altNamesEntry != null) { Reader altNamesReader = getReader(zip, altNamesEntry); Map<String, String> altNames = processAltNamesFile(altNamesReader); processReader(reader, altNames); } else { processReader(reader, null); } } if (deletedIdsEntry != null) { Reader reader = getReader(zip, deletedIdsEntry); processDeletedIdsReader(reader); } } catch (IOException e) { throw new RuntimeException("Error reading zip file", e); } }
From source file:org.ambraproject.wombat.controller.FeedbackController.java
private static Map<String, String> getUserSessionAttributes(HttpServletRequest request) { Map<String, String> headers = new LinkedHashMap<>(); for (String headerName : Collections.list(request.getHeaderNames())) { List<String> headerValues = Collections.list(request.getHeaders(headerName)); headers.put(headerName, headerValues.stream().collect(joinWithComma())); }/* w w w . j a v a2s . co m*/ headers.put("server-name", request.getServerName() + ":" + request.getServerPort()); headers.put("remote-addr", request.getRemoteAddr()); headers.put("local-addr", request.getLocalAddr() + ":" + request.getLocalPort()); /* * Keeping this in case more values get passed from the client other than just the visible form * fields */ for (String paramName : Collections.list(request.getParameterNames())) { String[] paramValues = request.getParameterValues(paramName); headers.put(paramName, Stream.of(paramValues).collect(joinWithComma())); } return headers; }