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;
}
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);
}
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();
}
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);
}
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;
}
Aggregations