move code to src/test
* so that it compiles and tests pass * fix some additional snip references in getting started
This commit is contained in:
parent
413df8e0f4
commit
59f53e1a22
289 changed files with 45 additions and 45 deletions
|
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2016-2017 Lightbend Inc. <http://www.lightbend.com/>
|
||||
*/
|
||||
package docs.stream.cookbook
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.zip.GZIPOutputStream
|
||||
|
||||
import akka.stream.impl.io.compression.GzipCompressor
|
||||
import akka.stream.scaladsl.Sink
|
||||
import akka.stream.scaladsl.Source
|
||||
import akka.util.ByteString
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class RecipeDecompress extends RecipeSpec {
|
||||
def gzip(s: String): ByteString = {
|
||||
val buf = new ByteArrayOutputStream()
|
||||
val out = new GZIPOutputStream(buf)
|
||||
try out.write(s.getBytes(StandardCharsets.UTF_8)) finally out.close()
|
||||
ByteString(buf.toByteArray)
|
||||
}
|
||||
|
||||
"Recipe for decompressing a Gzip stream" must {
|
||||
"work" in {
|
||||
val compressed = Source.single(gzip("Hello World"))
|
||||
|
||||
//#decompress-gzip
|
||||
import akka.stream.scaladsl.Compression
|
||||
val uncompressed = compressed.via(Compression.gunzip())
|
||||
.map(_.utf8String)
|
||||
//#decompress-gzip
|
||||
|
||||
Await.result(uncompressed.runWith(Sink.head), 3.seconds) should be("Hello World")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue