use of com.firenio.codec.http11.Cookie in project apps-android-wikipedia by wikimedia.
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 instagram-java-scraper by postaddictme.
the class CookieHashSet method addAll.
@Override
public void addAll(Collection<Cookie> cookies) {
for (Cookie cookie : cookies) {
CookieBox box = new CookieBox(cookie);
boxes.remove(box);
boxes.add(box);
}
}
use of com.firenio.codec.http11.Cookie in project apps-android-commons by commons-app.
the class SharedPreferenceCookieManager method saveFromResponse.
@Override
public synchronized void saveFromResponse(@NonNull HttpUrl url, @NonNull List<Cookie> cookies) {
if (cookies.isEmpty()) {
return;
}
boolean cookieJarModified = false;
for (Cookie cookie : cookies) {
// Default to the URI's domain if cookie's domain is not explicitly set
String domainSpec = TextUtils.isEmpty(cookie.domain()) ? url.uri().getAuthority() : cookie.domain();
if (!cookieJar.containsKey(domainSpec)) {
cookieJar.put(domainSpec, new ArrayList<>());
}
List<Cookie> cookieList = cookieJar.get(domainSpec);
if (cookie.expiresAt() < System.currentTimeMillis() || "deleted".equals(cookie.value())) {
Iterator<Cookie> i = cookieList.iterator();
while (i.hasNext()) {
if (i.next().name().equals(cookie.name())) {
i.remove();
cookieJarModified = true;
}
}
} else {
Iterator<Cookie> i = cookieList.iterator();
boolean exists = false;
while (i.hasNext()) {
Cookie c = i.next();
if (c.equals(cookie)) {
// an identical cookie already exists, so we don't need to update it.
exists = true;
break;
} else if (c.name().equals(cookie.name())) {
// it's a cookie with the same name, but different contents, so remove the
// current cookie, so that the new one will be added.
i.remove();
}
}
if (!exists) {
cookieList.add(cookie);
cookieJarModified = true;
}
}
}
if (cookieJarModified) {
persistCookies();
}
}
use of com.firenio.codec.http11.Cookie in project apps-android-commons by commons-app.
the class SharedPreferenceCookieManager method buildCookieList.
private void buildCookieList(@NonNull List<Cookie> outList, @NonNull List<Cookie> inList, @Nullable String prefix) {
Iterator<Cookie> i = inList.iterator();
boolean cookieJarModified = false;
while (i.hasNext()) {
Cookie cookie = i.next();
if (prefix != null && !cookie.name().startsWith(prefix)) {
continue;
}
// But wait, is the cookie expired?
if (cookie.expiresAt() < System.currentTimeMillis()) {
i.remove();
cookieJarModified = true;
} else {
outList.add(cookie);
}
}
if (cookieJarModified) {
persistCookies();
}
}
use of com.firenio.codec.http11.Cookie in project BaseProject by feer921.
the class SerializableCookie method bytesToCookie.
public static Cookie bytesToCookie(byte[] bytes) {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
Cookie cookie = null;
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
cookie = ((SerializableCookie) objectInputStream.readObject()).getCookie();
} catch (Exception e) {
OkLogger.printStackTrace(e);
}
return cookie;
}
Aggregations