List of usage examples for java.util Collections enumeration
public static <T> Enumeration<T> enumeration(final Collection<T> c)
From source file:com.discovery.darchrow.util.CollectionsUtil.java
/** * ??./* ww w . j a v a 2 s . co m*/ * * @param <T> * the generic type * @param collection * ? * @return Enumeration * @see Collections#enumeration(Collection) */ public static final <T> Enumeration<T> toEnumeration(final Collection<T> collection) { return Collections.enumeration(collection); }
From source file:io.inkstand.deployment.staticcontent.ZipFileResourceTest.java
@Test public void testList_dirEntry_fileList() throws Exception { //prepare//from ww w .j a v a 2s . com Enumeration enumeration = Collections.enumeration(Arrays.asList(zipEntry, dirEntry)); when(zipFile.entries()).thenReturn(enumeration); //act List<Resource> resources = subject_dir_resource.list(); //assert assertNotNull(resources); assertEquals(1, resources.size()); ZipFileResource res = (ZipFileResource) resources.get(0); assertEquals(FILE_ENTRY_PATH, res.getPath()); }
From source file:com.zextras.zimbradrive.UploadFileHttpHandler.java
private HttpEntity createUploadFileRequest(HttpServletRequest httpServletRequest, String formBoundary, Account userAccount) throws IOException { InputStream userRequestInputStream = httpServletRequest.getInputStream(); String userInfoPartsString = createUserInfoInFormStyle(userAccount, formBoundary); String internalFormPartsBoundary = getInternalBodyBoundary(formBoundary); List<InputStream> payloadStreamToSendToDrive = Arrays.asList( new ByteArrayInputStream(userInfoPartsString.getBytes()), new ByteArrayInputStream(internalFormPartsBoundary.getBytes()), userRequestInputStream // TODO: This inputStreams will be closed? );//from w w w . j ava 2 s .c om SequenceInputStream payloadToSendToDriveInputStream = new SequenceInputStream( Collections.enumeration(payloadStreamToSendToDrive)); int contentLength = httpServletRequest.getIntHeader(HTTP.CONTENT_LEN); int diffInternalFormPartsBoundaryAndFirstBodyBoundary = 2; // getFirstBodyBoundary(boundaryOfParts) - getInternalBodyBoundary(formBoundary) contentLength = contentLength + userInfoPartsString.length() + diffInternalFormPartsBoundaryAndFirstBodyBoundary; return new InputStreamEntity(payloadToSendToDriveInputStream, contentLength); }
From source file:com.google.gerrit.util.http.testutil.FakeHttpServletRequest.java
@Override public Enumeration<String> getHeaderNames() { return Collections.enumeration(headers.keySet()); }
From source file:it.anyplace.sync.core.configuration.ConfigurationService.java
private synchronized Properties export() { Properties properties = new Properties() { @Override//w ww . ja va2 s . co m public synchronized Enumeration<Object> keys() { List<String> list = (List) Collections.list(super.keys()); Collections.sort(list); return Collections.enumeration((List) list); } }; if (!isBlank(deviceName)) { properties.setProperty(DEVICE_NAME, deviceName); } if (!isBlank(deviceId)) { properties.setProperty(DEVICE_ID, deviceId); } FolderConfigList folderConfigList = new FolderConfigList(); for (FolderInfo folderInfo : folders.values()) { FolderConfig folderConfig = new FolderConfig(); folderConfig.setFolder(folderInfo.getFolder()); folderConfig.setLabel(folderInfo.getLabel()); folderConfigList.getFolders().add(folderConfig); } properties.setProperty(FOLDERS, gson.toJson(folderConfigList)); DeviceConfigList deviceConfigList = new DeviceConfigList(); for (DeviceInfo deviceInfo : peers.values()) { DeviceConfig deviceConfig = new DeviceConfig(); deviceConfig.setDeviceId(deviceInfo.getDeviceId()); deviceConfig.setName(deviceInfo.getName()); deviceConfigList.getDevices().add(deviceConfig); } properties.setProperty(PEERS, gson.toJson(deviceConfigList)); properties.setProperty(DATABASE, database.getAbsolutePath()); properties.setProperty(TEMP, temp.getAbsolutePath()); properties.setProperty(CACHE, cache.getAbsolutePath()); if (keystore != null) { properties.setProperty(KEYSTORE, BaseEncoding.base64().encode(keystore)); } if (!isBlank(keystoreAlgo)) { properties.setProperty(KEYSTORE_ALGO, keystoreAlgo); } properties.setProperty(DISCOVERY_SERVERS, Joiner.on(",").join(discoveryServers)); return properties; }
From source file:org.kuali.rice.kns.web.struts.form.pojo.PojoFormBase.java
/** * Populates the form with values from the current request. Uses instances of Formatter to convert strings to the Java types of * the properties to which they are bound. Values that can't be converted are cached in a map of unconverted values. Returns an * ActionErrors containing ActionMessage instances for each conversion error that occured, if any. *///from ww w .j ava 2 s . c o m @Override public void populate(HttpServletRequest request) { StopWatch watch = null; if (LOG.isDebugEnabled()) { watch = new StopWatch(); watch.start(); LOG.debug(WATCH_NAME + ": started"); } unconvertedValues.clear(); unknownKeys = new ArrayList(); addRequiredNonEditableProperties(); Map params = request.getParameterMap(); String contentType = request.getContentType(); String method = request.getMethod(); if ("POST".equalsIgnoreCase(method) && contentType != null && contentType.startsWith("multipart/form-data")) { Map fileElements = (HashMap) request.getAttribute(KRADConstants.UPLOADED_FILE_REQUEST_ATTRIBUTE_KEY); Enumeration names = Collections.enumeration(fileElements.keySet()); while (names.hasMoreElements()) { String name = (String) names.nextElement(); params.put(name, fileElements.get(name)); } } postprocessRequestParameters(params); /** * Iterate through request parameters, if parameter matches a form variable, get the property type, formatter and convert, * if not add to the unknowKeys map. */ Comparator<String> nestedPathComparator = new Comparator<String>() { public int compare(String prop1, String prop2) { Integer i1 = new Integer(prop1.split("\\.").length); Integer i2 = new Integer(prop2.split("\\.").length); return (i1.compareTo(i2)); } }; List<String> pathKeyList = new ArrayList<String>(params.keySet()); Collections.sort(pathKeyList, nestedPathComparator); for (String keypath : pathKeyList) { if (shouldPropertyBePopulatedInForm(keypath, request)) { Object param = params.get(keypath); //LOG.debug("(keypath,paramType)=(" + keypath + "," + param.getClass().getName() + ")"); populateForProperty(keypath, param, params); } } this.registerIsNewForm(false); if (LOG.isDebugEnabled()) { watch.stop(); LOG.debug(WATCH_NAME + ": " + watch.toString()); } }
From source file:com.google.gerrit.util.http.testutil.FakeHttpServletRequest.java
@Override public Enumeration<String> getHeaders(String name) { return Collections.enumeration(headers.get(name)); }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletHttpRequest.java
public Enumeration getLocales() { Enumeration enm = _httpRequest.getFieldValues(HttpFields.__AcceptLanguage, HttpFields.__separators); // handle no locale if (enm == null || !enm.hasMoreElements()) return Collections.enumeration(__defaultLocale); // sort the list in quality order List acceptLanguage = HttpFields.qualityList(enm); if (acceptLanguage.size() == 0) return Collections.enumeration(__defaultLocale); Object langs = null;//from w w w . ja va2 s.co m int size = acceptLanguage.size(); // convert to locals for (int i = 0; i < size; i++) { String language = (String) acceptLanguage.get(i); language = HttpFields.valueParameters(language, null); String country = ""; int dash = language.indexOf('-'); if (dash > -1) { country = language.substring(dash + 1).trim(); language = language.substring(0, dash).trim(); } langs = LazyList.ensureSize(langs, size); langs = LazyList.add(langs, new Locale(language, country)); } if (LazyList.size(langs) == 0) return Collections.enumeration(__defaultLocale); return Collections.enumeration(LazyList.getList(langs)); }
From source file:nl.armatiek.xslweb.web.servlet.XSLWebHttpServletRequest.java
@Override public Enumeration<String> getHeaders(String name) { return Collections.enumeration(new ArrayList<String>()); }
From source file:fr.fastconnect.factory.tibco.bw.maven.packaging.AbstractPackagingMojo.java
/** * <p>/*from w w w . j a v a2s. com*/ * This loads a properties file into a java.util.Properties object with * sorted keys.<br/><br/> * * <b>NB</b>: always use keys() method to browse the properties * </p> * * @param propertiesFile * @return * @throws ConfigurationException * @throws IOException */ protected Properties loadPropertiesFile(File propertiesFile) throws ConfigurationException, IOException { Properties properties = new Properties() { // sorted properties private static final long serialVersionUID = 7793482336210629858L; @Override public synchronized Enumeration<Object> keys() { return Collections.enumeration(new TreeSet<Object>(super.keySet())); } }; FileInputStream fileInputStream = new FileInputStream(propertiesFile); properties.load(fileInputStream); return properties; }