我有一个带scala的Enumeratee.map [Array [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]的每个长度但不是地图中的总大小?
如何获得总长度?