Last active
June 2, 2017 14:14
-
-
Save zikolach/b1cc837b33456b98d3fd2d6d8b4b7a4c to your computer and use it in GitHub Desktop.
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
import akka.actor.ActorSystem | |
import akka.event.Logging | |
import akka.http.scaladsl.Http | |
import akka.http.scaladsl.client.RequestBuilding._ | |
import akka.http.scaladsl.unmarshalling.Unmarshal | |
import akka.stream.ActorMaterializer | |
import scala.concurrent.Await | |
import scala.concurrent.duration.Duration.Inf | |
object MainError { | |
private implicit val system = ActorSystem() | |
private implicit val materializer = ActorMaterializer() | |
private implicit val executionContext = system.dispatcher | |
val log = Logging(system, getClass) | |
def main(args: Array[String]): Unit = { | |
try { | |
val request = Get("https://example.com") | |
val bytesFuture = Http(system).singleRequest(request).flatMap(response => { | |
Unmarshal(response.entity.withoutSizeLimit()).to[Array[Byte]] | |
}) | |
val bytes = Await.result(bytesFuture, Inf) | |
log.info(s"Size ${bytes.length}") | |
} catch { | |
case err: Throwable => log.error(err.getMessage) | |
} finally { | |
Await.ready(Http().shutdownAllConnectionPools(), Inf) | |
Await.ready(system.terminate(), Inf) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment