Slide 44
Slide 44 text
([JQ$PNQSFTT'MPX
class GzipCompressorStage extends GraphStage[FlowShape[ByteString, ByteString]] {
val compressor = new GzipCompressor()
val in: Inlet[ByteString] = Inlet("GzipCompressorStage")
val out: Outlet[ByteString] = Outlet("GzipCompressorStage")
override def shape: FlowShape[ByteString, ByteString] = FlowShape(in, out)
@scala.throws[Exception](classOf[Exception])
override def createLogic(inheritedAttributes: Attributes) =
new GraphStageLogic(shape) {
setHandler(in, new InHandler {
// ্ྲྀ͔ΒͷByteStringΛѹॖͯ͠Լྲྀʹྲྀ͢
@scala.throws[Exception](classOf[Exception])
override def onPush(): Unit =
push(out, compressor.compressAndFlush(grab(in)))
// ্ྲྀ͕ऴྃͨ͠Β࠷ޙͷByteStringΛѹॖͯ͠Լྲྀʹྲྀ͢
@scala.throws[Exception](classOf[Exception])
override def onUpstreamFinish(): Unit =
{ push(out, compressor.finish()); super.onUpstreamFinish() }
})
setHandler(out, new OutHandler {
override def onPull(): Unit = {
pull(in)
}
})
}
}
(SBQI4UBHFΛ͏ͱෳࡶͳ
4PVSDF
'MPX
4JOL͕ఆٛͰ͖Δ Χ
ελϜεςʔδ
ɻάϥϑͷߏஙఔ
ͳΒ(SBQI%4-Ͱهड़Մೳɻ