scala enumeratee得到长度

时间:2014-07-18 11:17:07

标签: scala playframework playframework-2.0 scala-2.10 scala-2.8

我有一个带scala的Enumeratee.map [A​​rray [Byte]]

class AccessLog extends EssentialFilter {
  def apply(next: EssentialAction) = new EssentialAction {
    lazy val processor: RequestStatsProcessor = RequestStatsProcessor.getInstance
    def apply(rh: RequestHeader) = {
      val start = System.currentTimeMillis
      def writeableEnumeratee[A](writeable: Writeable[A]): Enumeratee[A, Array[Byte]] = Enumeratee.map(a => writeable.transform(a))
      var size: Long = 0;
      def logTime(response: PlainResult): Result = response match {
        case simple @ SimpleResult(header, body) => {
          val time = System.currentTimeMillis - start

          val en = Enumeratee.map[Array[Byte]] { item =>
            size = size + item.length
            var requestInfo: RequestInfo = new RequestInfo(start, rh, response, size)
            processor.setRequest(requestInfo)
            processor.process
            item
          }
          SimpleResult(header, body &> writeableEnumeratee(simple.writeable) &> en)
        }
        case _ => response
      }
      next(rh).map {
        case plain: PlainResult => logTime(plain)
        case async: AsyncResult => async.transform(logTime)
      }
    }
  }
}

如果我这样写,我会得到数组[Byte]的每个长度但不是地图中的总大小?

如何获得总长度?

0 个答案:

没有答案