-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alikemal.ocalan
committed
Jan 16, 2021
1 parent
6bbd56a
commit 374ffce
Showing
6 changed files
with
70 additions
and
86 deletions.
There are no files selected for viewing
62 changes: 0 additions & 62 deletions
62
src/main/java/com/github/alikemalocalan/instastorysaver/SerializableCookieJar.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/scala/com/github/alikemalocalan/instastorysaver/model/SerializableCookieJar.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.github.alikemalocalan.instastorysaver.model | ||
|
||
import com.github.alikemalocalan.instastorysaver.Utils | ||
import okhttp3.{Cookie, CookieJar, HttpUrl} | ||
|
||
import java.io.{ObjectInputStream, ObjectOutputStream} | ||
import java.util | ||
import scala.collection.mutable | ||
import scala.collection.mutable.ListBuffer | ||
import scala.jdk.CollectionConverters._ | ||
|
||
class SerializableCookieJar extends CookieJar with Serializable { | ||
|
||
val map: mutable.Map[String, ListBuffer[SerializableCookie]] = mutable.Map[String, ListBuffer[SerializableCookie]]() | ||
|
||
override def loadForRequest(httpUrl: HttpUrl): util.List[Cookie] = { | ||
map.getOrElse(httpUrl.host(), ListBuffer[SerializableCookie]().empty) | ||
.map(c => c.cookie) | ||
.asJava | ||
} | ||
|
||
override def saveFromResponse(httpUrl: HttpUrl, list: java.util.List[Cookie]): Unit = { | ||
val cookies = list.asScala.map(SerializableCookie).to(ListBuffer) | ||
|
||
if (map.contains(httpUrl.host())) { | ||
map(httpUrl.host()).addAll(cookies) | ||
} else map.put(httpUrl.host(), cookies) | ||
} | ||
|
||
case class SerializableCookie(var cookie: Cookie) extends Serializable { | ||
|
||
private def writeObject(out: ObjectOutputStream): Unit = { | ||
Utils.writeObject(cookie, out) | ||
} | ||
|
||
private def readObject(in: ObjectInputStream): Unit = { | ||
cookie = Utils.readObject(in) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters