Search in sources :

Example 96 with Cookie

use of com.firenio.codec.http11.Cookie in project YhLibraryForAndroid by android-coco.

the class PersistentCookieStore method decodeCookie.

protected Cookie decodeCookie(String cookieString) {
    byte[] bytes = hexStringToByteArray(cookieString);
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
    Cookie cookie = null;
    try {
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        cookie = ((SerializableHttpCookie) objectInputStream.readObject()).getCookie();
    } catch (IOException e) {
        LogUtils.d(LOG_TAG, "IOException in decodeCookie", e);
    } catch (ClassNotFoundException e) {
        LogUtils.d(LOG_TAG, "ClassNotFoundException in decodeCookie", e);
    }
    return cookie;
}
Also used : Cookie(okhttp3.Cookie) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 97 with Cookie

use of com.firenio.codec.http11.Cookie in project apps-android-commons by commons-app.

the class CookieManagerTypeAdapter method read.

@Override
public SharedPreferenceCookieManager read(JsonReader in) throws IOException {
    Map<String, List<Cookie>> map = new HashMap<>();
    in.beginObject();
    while (in.hasNext()) {
        String key = in.nextName();
        List<Cookie> list = new ArrayList<>();
        map.put(key, list);
        in.beginArray();
        HttpUrl url = HttpUrl.parse(WikiSite.DEFAULT_SCHEME + "://" + key);
        while (in.hasNext()) {
            String str = in.nextString();
            if (url != null) {
                list.add(Cookie.parse(url, str));
            }
        }
        in.endArray();
    }
    in.endObject();
    return new SharedPreferenceCookieManager(map);
}
Also used : Cookie(okhttp3.Cookie) HashMap(java.util.HashMap) SharedPreferenceCookieManager(org.wikipedia.dataclient.SharedPreferenceCookieManager) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) HttpUrl(okhttp3.HttpUrl)

Example 98 with Cookie

use of com.firenio.codec.http11.Cookie in project apps-android-commons by commons-app.

the class CookieManagerTypeAdapter method write.

@Override
public void write(JsonWriter out, SharedPreferenceCookieManager cookies) throws IOException {
    Map<String, List<Cookie>> map = cookies.getCookieJar();
    out.beginObject();
    for (String key : map.keySet()) {
        out.name(key).beginArray();
        for (Cookie cookie : map.get(key)) {
            out.value(cookie.toString());
        }
        out.endArray();
    }
    out.endObject();
}
Also used : Cookie(okhttp3.Cookie) List(java.util.List) ArrayList(java.util.ArrayList)

Example 99 with Cookie

use of com.firenio.codec.http11.Cookie in project BaseProject by feer921.

the class MemoryCookieStore method saveCookie.

@Override
public synchronized void saveCookie(HttpUrl url, Cookie cookie) {
    List<Cookie> cookies = memoryCookies.get(url.host());
    List<Cookie> needRemove = new ArrayList<>();
    for (Cookie item : cookies) {
        if (cookie.name().equals(item.name())) {
            needRemove.add(item);
        }
    }
    cookies.removeAll(needRemove);
    cookies.add(cookie);
}
Also used : Cookie(okhttp3.Cookie) ArrayList(java.util.ArrayList)

Example 100 with Cookie

use of com.firenio.codec.http11.Cookie in project BaseProject by feer921.

the class DBCookieStore method loadCookie.

/**
 * 根据当前url获取所有需要的cookie,只返回没有过期的cookie
 */
@Override
public synchronized List<Cookie> loadCookie(HttpUrl url) {
    List<Cookie> ret = new ArrayList<>();
    if (!cookies.containsKey(url.host()))
        return ret;
    List<SerializableCookie> query = CookieManager.getInstance().query("host=?", new String[] { url.host() });
    for (SerializableCookie serializableCookie : query) {
        Cookie cookie = serializableCookie.getCookie();
        if (isCookieExpired(cookie)) {
            removeCookie(url, cookie);
        } else {
            ret.add(cookie);
        }
    }
    return ret;
}
Also used : Cookie(okhttp3.Cookie) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie) ArrayList(java.util.ArrayList) SerializableCookie(com.lzy.okgo.cookie.SerializableCookie)

Aggregations

Cookie (okhttp3.Cookie)102 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)20 HttpUrl (okhttp3.HttpUrl)18 ByteArrayInputStream (java.io.ByteArrayInputStream)16 ObjectInputStream (java.io.ObjectInputStream)16 SharedPreferences (android.content.SharedPreferences)12 Context (android.content.Context)8 HashMap (java.util.HashMap)8 List (java.util.List)8 Map (java.util.Map)8 Test (org.junit.Test)8 Response (okhttp3.Response)7 SerializableCookie (com.lzy.okgo.cookie.SerializableCookie)6 Request (okhttp3.Request)6 SuppressLint (android.annotation.SuppressLint)4 CookieManager (android.webkit.CookieManager)4 EhCookieStore (com.hippo.ehviewer.client.EhCookieStore)4 OnClick (butterknife.OnClick)3 SerializableCookie (com.franmontiel.persistentcookiejar.persistence.SerializableCookie)3