Example usage for com.google.common.collect Iterators forEnumeration

List of usage examples for com.google.common.collect Iterators forEnumeration

Introduction

In this page you can find the example usage for com.google.common.collect Iterators forEnumeration.

Prototype

public static <T> UnmodifiableIterator<T> forEnumeration(final Enumeration<T> enumeration) 

Source Link

Document

Adapts an Enumeration to the Iterator interface.

Usage

From source file:com.google.cloud.dataflow.sdk.util.ZipFiles.java

/**
 * Returns a {@link FluentIterable} of all the entries in the given zip file.
 *//* w  w w  . j  av  a  2  s .  c  o  m*/
// unmodifiable Iterator<? extends ZipEntry> can be safely cast
// to Iterator<ZipEntry>
@SuppressWarnings("unchecked")
static FluentIterable<ZipEntry> entries(final ZipFile file) {
    checkNotNull(file);
    return new FluentIterable<ZipEntry>() {
        @Override
        public Iterator<ZipEntry> iterator() {
            return (Iterator<ZipEntry>) Iterators.forEnumeration(file.entries());
        }
    };
}

From source file:co.cask.common.lang.CombineClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    Set<URL> urls = Sets.newHashSet();
    for (ClassLoader classLoader : delegates) {
        Iterators.addAll(urls, Iterators.forEnumeration(classLoader.getResources(name)));
    }//  w  ww. j a v  a  2 s  . c o m
    return Iterators.asEnumeration(urls.iterator());
}

From source file:org.ambraproject.rhino.rest.LoggingInterceptor.java

/**
 * Build a message describing a request.
 *
 * @param request the request to describe
 * @return the description//from  w w  w  . j  a  v  a  2s. c  om
 */
private static String describe(HttpServletRequest request) {
    StringBuilder message = new StringBuilder();
    message.append(request.getMethod()).append(' ').append(request.getRequestURI());
    String queryString = request.getQueryString();
    if (queryString != null) {
        message.append(" ? ").append(queryString);
    }
    message.append('\n');

    // Append a list of headers
    for (Enumeration headerNames = request.getHeaderNames(); headerNames.hasMoreElements();) {
        String headerName = (String) headerNames.nextElement();
        message.append(INDENT).append(asStringLiteral(headerName)).append(": ");
        Enumeration<?> headers = request.getHeaders(headerName);
        Iterator<String> headerStrings = Iterators.transform(Iterators.forEnumeration(headers),
                LoggingInterceptor::asStringLiteral);
        JOINER.appendTo(message, headerStrings);
        message.append('\n');
    }

    return message.toString();
}

From source file:io.druid.initialization.ExtensionFirstClassLoader.java

@Override
public Enumeration<URL> getResources(final String name) throws IOException {
    final List<URL> urls = new ArrayList<>();
    Iterators.addAll(urls, Iterators.forEnumeration(super.getResources(name)));
    Iterators.addAll(urls, Iterators.forEnumeration(druidLoader.getResources(name)));
    return Iterators.asEnumeration(urls.iterator());
}

From source file:org.richfaces.model.SwingTreeNodeDataModelImpl.java

public Iterator<TreeDataModelTuple> children() {
    Iterator<TreeNode> children = Iterators.forEnumeration((Enumeration<TreeNode>) getData().children());
    return new IterableDataTuplesIterator(getRowKey(), children);
}

From source file:org.sonar.api.utils.LocalizedMessages.java

@Override
public Enumeration<String> getKeys() {
    return new Enumeration<String>() {
        private Set<String> keys = new HashSet<String>();

        // Set iterator to simulate enumeration
        private Iterator<String> i;

        // Constructor
        {/*from  w  w w  . j  a va 2  s .  c o  m*/
            for (ResourceBundle b : bundles) {
                keys.addAll(Lists.newArrayList(Iterators.forEnumeration(b.getKeys())));
            }
            i = keys.iterator();
        }

        public boolean hasMoreElements() {
            return i.hasNext();
        }

        public String nextElement() {
            return i.next();
        }
    };
}

From source file:co.cask.cdap.common.lang.CombineClassLoader.java

@Override
protected Enumeration<URL> findResources(String name) throws IOException {
    // Using LinkedHashSet to preserve the ordering
    Set<URL> urls = Sets.newLinkedHashSet();
    for (ClassLoader classLoader : delegates) {
        Iterators.addAll(urls, Iterators.forEnumeration(classLoader.getResources(name)));
    }/*from w ww . ja  va  2  s . c o m*/
    return Iterators.asEnumeration(urls.iterator());
}

From source file:org.obiba.security.KeyStoreManager.java

public Set<String> listAliases() {
    try {/*from  w ww.  j  a va  2s  .  c  o m*/
        return ImmutableSet.copyOf(Iterators.forEnumeration(store.aliases()));
    } catch (KeyStoreException e) {
        throw new RuntimeException(e);
    }
}

From source file:pl.softech.tutorial.jee.workshop.WelcomeServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*w w w  .j av  a2 s. c  o  m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet WelcomeServlet</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet WelcomeServlet at " + request.getContextPath() + "</h1>");
        out.println(new Date());
        out.println("</br>" + getServletConfig().getInitParameter("email"));

        out.println("</br>");

        String param1 = request.getParameter("param1");
        String[] params1 = request.getParameterValues("param1");
        String param2 = request.getParameter("param2");

        out.println("<ul>");
        out.println("<li>param1=" + param1 + "</li>");
        out.println("<li>param2=" + param2 + "</li>");

        out.println("</ul>");

        out.println("<h1>Request parameters</h1>");
        out.println("<ul>");
        for (Enumeration<String> e = request.getParameterNames(); e.hasMoreElements();) {
            String paramName = e.nextElement();
            out.println("<li>" + paramName + "=" + request.getParameter(paramName) + "</li>");
        }

        out.println("</ul>");

        out.println("<h1>Request parameters by Map</h1>");
        out.println("<ul>");
        for (Map.Entry<String, String[]> e : request.getParameterMap().entrySet()) {

            //                out.println("<li>" + e.getKey() + "=");
            //                out.println(Joiner.on(", ").join(e.getValue()));
            //                out.println("</li>");
            out.println(String.format("<li>%s = %s</li>", e.getKey(), Joiner.on(", ").join(e.getValue())));

        }

        out.println("</ul>");

        out.println("<h1>Request headers</h1>");
        out.println("<ul>");

        for (Enumeration<String> e = request.getHeaderNames(); e.hasMoreElements();) {
            String paramName = e.nextElement();
            out.println(String.format("<li>%s: [%s]</li>", paramName,
                    Joiner.on(", ").join(Iterators.forEnumeration(request.getHeaders(paramName)))));
        }

        out.println("</ul>");

        out.println("</body>");
        out.println("</html>");
    }
}

From source file:org.glowroot.config.PluginCacheBase.java

private static ImmutableList<URL> getResources(String resourceName) throws IOException {
    ClassLoader loader = PluginCache.class.getClassLoader();
    if (loader == null) {
        return ImmutableList.copyOf(Iterators.forEnumeration(ClassLoader.getSystemResources(resourceName)));
    }//  ww w.j  a  v a 2s. c  o  m
    return ImmutableList.copyOf(Iterators.forEnumeration(loader.getResources(resourceName)));
}