Example usage for com.google.common.net UriEscapers uriEscaper

List of usage examples for com.google.common.net UriEscapers uriEscaper

Introduction

In this page you can find the example usage for com.google.common.net UriEscapers uriEscaper.

Prototype

public static Escaper uriEscaper() 

Source Link

Document

Returns an Escaper instance that escapes Java chars so they can be safely included in URIs.

Usage

From source file:com.google.walkaround.wave.server.rpc.ContactsHandler.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String encodedAddress = UriEscapers.uriEscaper().escape(user.getAddress());
    if (!userContext.hasOAuthCredentials()) {
        // Return an empty set of contacts; the client will show unknown avatars
        // and never call PhotosHandler.
        printJson(new ContactFeed(), encodedAddress, resp);
        return;//www.  j av  a  2  s .co  m
    }
    Pair<Integer, Integer> range = getRange(req);
    log.info("Fetching contacts for: " + user + ", [" + range.first + ", " + range.second + ")");
    URL url = new URL(FEED_URL + encodedAddress + "/thin" + "?start-index=" + range.first + "&max-results="
            + (range.second - range.first));
    ContactFeed results;
    try {
        results = contacts.get().getFeed(url, ContactFeed.class);
    } catch (ServiceException e) {
        throw new IOException("Contact fetch failed: ", e);
    }
    log.info("Fetched " + results.getEntries().size() + " contacts for " + user);

    // Support ?format=html for debugging.
    if ("html".equals(req.getParameter("format"))) {
        printHtml(results, encodedAddress, resp);
    } else {
        printJson(results, encodedAddress, resp);
    }
}