List of usage examples for java.util Collections enumeration
public static <T> Enumeration<T> enumeration(final Collection<T> c)
From source file:org.opennms.netmgt.config.snmp.Definition.java
/** * Method enumerateSpecific.// w w w .j ava 2 s . co m * * @return an Enumeration over all possible elements of this * collection */ public Enumeration<String> enumerateSpecific() { return Collections.enumeration(this._specificList); }
From source file:org.apache.axis2.deployment.DeploymentClassLoader.java
/** * Returns an Enumeration of URLs representing all of the resources * on the URL search path having the specified name. * * @param resource the resource name//from w w w. j a va2 s.c o m * @exception IOException if an I/O exception occurs * @return an <code>Enumeration</code> of <code>URL</code>s */ public Enumeration findResources(String resource) throws IOException { ArrayList resources = new ArrayList(); Enumeration e = super.findResources(resource); while (e.hasMoreElements()) { resources.add(e.nextElement()); } for (int i = 0; embedded_jars != null && i < embedded_jars.size(); i++) { String libjar_name = (String) embedded_jars.get(i); try { InputStream in = getJarAsStream(libjar_name); ZipInputStream zin = new ZipInputStream(in); ZipEntry entry; String entryName; while ((entry = zin.getNextEntry()) != null) { entryName = entry.getName(); if (entryName != null && entryName.endsWith(resource)) { byte[] raw = IOUtils.toByteArray(zin); resources.add(new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName, new ByteUrlStreamHandler(raw))); } } } catch (Exception ex) { throw new RuntimeException(ex); } } return Collections.enumeration(resources); }
From source file:org.ireland.jnetty.dispatch.filter.FilterConfigImpl.java
/** * Gets the init params */ @Override public Enumeration<String> getInitParameterNames() { return Collections.enumeration(_initParams.keySet()); }
From source file:com.bluexml.side.framework.alfresco.shareLanguagePicker.connector.MyHttpRequestServletAdaptator.java
/** * @param name/*from www. j a v a 2s.co m*/ * @return * @see javax.servlet.http.HttpServletRequest#getHeaders(java.lang.String) */ public Enumeration<?> getHeaders(String name) { return Collections.enumeration(headers.getValues(name)); }
From source file:com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequest.java
@Override public Enumeration<String> getHeaders(String s) { String headerValue = getHeaderCaseInsensitive(s); if (headerValue == null) { return Collections.enumeration(new ArrayList<String>()); }/*from www . j a va 2 s. c o m*/ List<String> valueCollection = new ArrayList<>(); valueCollection.add(headerValue); return Collections.enumeration(valueCollection); }
From source file:net.ontopia.utils.ontojsp.FakeServletContext.java
@Override public Enumeration<Servlet> getServlets() { return Collections.enumeration(Collections.<Servlet>emptySet()); }
From source file:com.liferay.util.servlet.UploadServletRequest.java
public Enumeration getParameterNames() { List parameterNames = new ArrayList(); Enumeration enu = super.getParameterNames(); while (enu.hasMoreElements()) { String name = (String) enu.nextElement(); if (!_params.containsKey(name)) { parameterNames.add(name);// w ww .j a v a 2s . c o m } } Iterator itr = _params.keySet().iterator(); while (itr.hasNext()) { String name = (String) itr.next(); parameterNames.add(name); } return Collections.enumeration(parameterNames); }
From source file:it.anyplace.sync.bep.BlockPuller.java
public FileDownloadObserver pullBlocks(FileBlocks fileBlocks) throws InterruptedException { logger.info("pulling file = {}", fileBlocks); checkArgument(connectionHandler.hasFolder(fileBlocks.getFolder()), "supplied connection handler %s will not share folder %s", connectionHandler, fileBlocks.getFolder());//from ww w . j a v a 2s. c om final Object lock = new Object(); final AtomicReference<Exception> error = new AtomicReference<>(); final Object listener = new Object() { @Subscribe public void handleResponseMessageReceivedEvent(ResponseMessageReceivedEvent event) { synchronized (lock) { try { if (!requestIds.contains(event.getMessage().getId())) { return; } checkArgument(equal(event.getMessage().getCode(), ErrorCode.NO_ERROR), "received error response, code = %s", event.getMessage().getCode()); byte[] data = event.getMessage().getData().toByteArray(); String hash = BaseEncoding.base16().encode(Hashing.sha256().hashBytes(data).asBytes()); blockCache.pushBlock(data); if (missingHashes.remove(hash)) { blocksByHash.put(hash, data); logger.debug("aquired block, hash = {}", hash); lock.notify(); } else { logger.warn("received not-needed block, hash = {}", hash); } } catch (Exception ex) { error.set(ex); lock.notify(); } } } }; FileDownloadObserver fileDownloadObserver = new FileDownloadObserver() { private long getReceivedData() { return blocksByHash.size() * BLOCK_SIZE; } private long getTotalData() { return (blocksByHash.size() + missingHashes.size()) * BLOCK_SIZE; } @Override public double getProgress() { return isCompleted() ? 1d : getReceivedData() / ((double) getTotalData()); } @Override public String getProgressMessage() { return (Math.round(getProgress() * 1000d) / 10d) + "% " + FileUtils.byteCountToDisplaySize(getReceivedData()) + " / " + FileUtils.byteCountToDisplaySize(getTotalData()); } @Override public boolean isCompleted() { return missingHashes.isEmpty(); } @Override public void checkError() { if (error.get() != null) { throw new RuntimeException(error.get()); } } @Override public double waitForProgressUpdate() throws InterruptedException { if (!isCompleted()) { synchronized (lock) { checkError(); lock.wait(); checkError(); } } return getProgress(); } @Override public InputStream getInputStream() { checkArgument(missingHashes.isEmpty(), "pull failed, some blocks are still missing"); List<byte[]> blockList = Lists .newArrayList(Lists.transform(hashList, Functions.forMap(blocksByHash))); return new SequenceInputStream(Collections .enumeration(Lists.transform(blockList, new Function<byte[], ByteArrayInputStream>() { @Override public ByteArrayInputStream apply(byte[] data) { return new ByteArrayInputStream(data); } }))); } @Override public void close() { missingHashes.clear(); hashList.clear(); blocksByHash.clear(); try { connectionHandler.getEventBus().unregister(listener); } catch (Exception ex) { } if (closeConnection) { connectionHandler.close(); } } }; try { synchronized (lock) { hashList.addAll(Lists.transform(fileBlocks.getBlocks(), new Function<BlockInfo, String>() { @Override public String apply(BlockInfo block) { return block.getHash(); } })); missingHashes.addAll(hashList); for (String hash : missingHashes) { byte[] block = blockCache.pullBlock(hash); if (block != null) { blocksByHash.put(hash, block); missingHashes.remove(hash); } } connectionHandler.getEventBus().register(listener); for (BlockInfo block : fileBlocks.getBlocks()) { if (missingHashes.contains(block.getHash())) { int requestId = Math.abs(new Random().nextInt()); requestIds.add(requestId); connectionHandler.sendMessage(Request.newBuilder().setId(requestId) .setFolder(fileBlocks.getFolder()).setName(fileBlocks.getPath()) .setOffset(block.getOffset()).setSize(block.getSize()) .setHash(ByteString.copyFrom(BaseEncoding.base16().decode(block.getHash()))) .build()); logger.debug("sent request for block, hash = {}", block.getHash()); } } return fileDownloadObserver; } } catch (Exception ex) { fileDownloadObserver.close(); throw ex; } }
From source file:org.springframework.mock.web.portlet.MockPortletContext.java
@Override public Enumeration<String> getAttributeNames() { return Collections.enumeration(this.attributes.keySet()); }
From source file:net.ontopia.utils.ontojsp.FakeServletContext.java
@Override public Enumeration<String> getServletNames() { return Collections.enumeration(Collections.<String>emptySet()); }