Java源码示例:com.franmontiel.persistentcookiejar.persistence.SerializableCookie
示例1
@Override
public List<Cookie> loadAll() {
List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
String serializedCookie = (String) entry.getValue();
Cookie cookie = new SerializableCookie().decode(serializedCookie);
if (cookie != null) {
cookies.add(cookie);
}
}
return cookies;
}
示例2
@Override
public void saveAll(Collection<Cookie> cookies) {
SharedPreferences.Editor editor = sharedPreferences.edit();
for (Cookie cookie : cookies) {
editor.putString(createCookieKey(cookie), new SerializableCookie().encode(cookie));
}
editor.apply();
}
示例3
@Override
public List<Cookie> loadAll() {
List<Cookie> cookies = new ArrayList<>(sharedPreferences.getAll().size());
for (Map.Entry<String, ?> entry : sharedPreferences.getAll().entrySet()) {
String serializedCookie = (String) entry.getValue();
Cookie cookie = new SerializableCookie().decode(serializedCookie);
if (cookie != null) {
cookies.add(cookie);
}
}
return cookies;
}
示例4
@Override
public void saveAll(Collection<Cookie> cookies) {
SharedPreferences.Editor editor = sharedPreferences.edit();
for (Cookie cookie : cookies) {
editor.putString(createCookieKey(cookie), new SerializableCookie().encode(cookie));
}
editor.apply();
}
示例5
@Test
public void cookieSerialization() throws Exception {
Cookie cookie = TestCookieCreator.createPersistentCookie(false);
String serializedCookie = new SerializableCookie().encode(cookie);
Cookie deserializedCookie = new SerializableCookie().decode(serializedCookie);
assertEquals(cookie, deserializedCookie);
}
示例6
@Test
public void hostOnlyDomainCookieSerialization() throws Exception {
Cookie cookie = TestCookieCreator.createPersistentCookie(true);
String serializedCookie = new SerializableCookie().encode(cookie);
Cookie deserializedCookie = new SerializableCookie().decode(serializedCookie);
assertEquals(cookie, deserializedCookie);
}
示例7
@Test
public void nonPersistentCookieSerialization() throws Exception {
Cookie cookie = TestCookieCreator.createNonPersistentCookie();
String serializedCookie = new SerializableCookie().encode(cookie);
Cookie deserializedCookie = new SerializableCookie().decode(serializedCookie);
assertEquals(cookie, deserializedCookie);
}