Java 8 CookieStore - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 CookieStore class.

This code example shows how to use the following methods:add, get, getCookies, remove
     *  
     * @since 1.6 
     */ 
    public void test_get_LURI() throws URISyntaxException { 
        try { 
            cookieStore.get(null);
            fail("should throw NullPointerException");
        } catch (NullPointerException e) {
            // expected 
        } 
 
        URI uri1 = new URI("http://get.uri1.test.org");
        List<HttpCookie> list = cookieStore.get(uri1);
        assertTrue(list.isEmpty());
        assertTrue(list instanceof ArrayList);
 
        HttpCookie cookie1 = new HttpCookie("cookie_name1", "cookie_value1");
        HttpCookie cookie2 = new HttpCookie("cookie_name2", "cookie_value2");
        cookieStore.add(uri1, cookie1);
        cookieStore.add(uri1, cookie2);

6
CodeRank
This code example shows how to use the following methods:removeAll
  public static boolean clearCookies(CookieHandler cookieHandler) {
    if (cookieHandler instanceof CookieManager) {
      CookieManager cookieManager = (CookieManager) cookieHandler;
      CookieStore cookieStore = cookieManager.getCookieStore();
      if (cookieStore != null) {
        cookieStore.removeAll();
        return true; 
      } 
    } 
    return false; 
  } 
 
  /** 
   * Creates a new NfcAdapter instance. 
   */ 
  public static NfcAdapter newNfcAdapter(Context context) {
    return NfcAdapter.getDefaultAdapter(context);
  } 
 
  public static void enableNFCWriteMode(Activity activity, NfcAdapter nfcAdapter, String textToWrite){
5
CodeRank
This code example shows how to use the following methods:add
    } 
 
    @Override 
    public void add(URI uri, HttpCookie cookie)
    { 
        delegate.add(uri, cookie);
    } 
 
    @Override 
    public List<HttpCookie> get(URI uri)
    { 
        return delegate.get(uri);
    } 
 
    @Override 
    public List<HttpCookie> getCookies()
    { 
        return delegate.getCookies();
    } 
 
4
CodeRank
This code example shows how to use the following methods:add
		 
		CookieStore store = manager.getCookieStore();
 
		try { 
			HttpCookie cookie = new HttpCookie(key, value);
			store.add(new URI(domain), cookie);
		} catch (URISyntaxException e) {
			Log.e(TAG, e.getMessage());
			e.printStackTrace();
		} 
	} 
	 
	@SuppressWarnings("unchecked") 
	public void addCookies(String url, Map<String, String> cookies) {
		if ((url == null) || (cookies == null) || (cookies.size() == 0)) {
			return; 
		} 
 
		String domain = NetHelper.getDomain(url);
		 
4
CodeRank
This code example shows how to use the following methods:get
        CookieStore cookieStore = getHttpClient().getCookieStore();
        if (cookieStore != null)
        { 
            StringBuilder cookies = null;
            if (uri != null)
                cookies = convertCookies(cookieStore.get(uri), null);
            cookies = convertCookies(request.getCookies(), cookies);
            if (cookies != null)
                request.header(HttpHeader.COOKIE.asString(), cookies.toString());
        } 
 
        // Authentication 
        applyAuthentication(request, proxy != null ? proxy.getURI() : null);
        applyAuthentication(request, uri);
    } 
 
    private StringBuilder convertCookies(List<HttpCookie> cookies, StringBuilder builder)
    { 
        for (int i = 0; i < cookies.size(); ++i)
        { 
4
CodeRank
This code example shows how to use the following methods:getCookies
		return cookieStore.get(uri);
	} 
 
	@Override 
	public List<HttpCookie> getCookies() {
		return cookieStore.getCookies();
	} 
 
	@Override 
	public List<URI> getURIs() {
		return cookieStore.getURIs();
	} 
 
	@Override 
	public boolean remove(URI uri, HttpCookie cookie) {
		return cookieStore.remove(uri, cookie);
	} 
 
	@Override 
	public boolean removeAll() { 
4
CodeRank
This code example shows how to use the following methods:removeAll
		return cookieStore.remove(uri, cookie);
	} 
 
	@Override 
	public boolean removeAll() { 
		return cookieStore.removeAll();
	} 
 
	public String getCookie(String key) {
		for (HttpCookie c : cookieStore.getCookies()) {
			if (c.getName().equals(key)) {
				return c.getValue();
			} 
		} 
		return null; 
	} 
} 
4
CodeRank
This code example shows how to use the following methods:removeAll
	  public static boolean clearCookies(CookieHandler cookieHandler) {
	    if (cookieHandler instanceof CookieManager) {
	      CookieManager cookieManager = (CookieManager) cookieHandler;
	      CookieStore cookieStore = cookieManager.getCookieStore();
	      if (cookieStore != null) {
	        cookieStore.removeAll();
	        return true; 
	      } 
	    } 
	    return false; 
	  } 
 
	 
} 
4
CodeRank
This code example shows how to use the following methods:removeAll
  public static boolean clearCookies(CookieHandler cookieHandler) {
    if (cookieHandler instanceof CookieManager) {
      CookieManager cookieManager = (CookieManager) cookieHandler;
      CookieStore cookieStore = cookieManager.getCookieStore();
      if (cookieStore != null) {
        cookieStore.removeAll();
        return true; 
      } 
    } 
    return false; 
  } 
} 
4
CodeRank
This code example shows how to use the following methods:removeAll
    } 
 
    @Override 
    protected void doStop() throws ExceptioncookieStore.removeAll();
        decoderFactories.clear();
        handlers.clear();
 
        for (HttpDestination destination : destinations.values())
            destination.close();
        destinations.clear();
 
        requestListeners.clear();
        authenticationStore.clearAuthentications();
        authenticationStore.clearAuthenticationResults();
 
        super.doStop(); 
    } 
 
3
CodeRank

Related Java 8 CookieStore Questions & Answers:

See Code Examples for Java 8 CookieStore Methods: