All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twitter.finatra.json.internal.streaming.JsonStreamParser.scala Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package com.twitter.finatra.json.internal.streaming

import com.twitter.concurrent.AsyncStream
import com.twitter.finatra.json.FinatraObjectMapper
import com.twitter.io.{Buf, Reader}
import javax.inject.{Inject, Singleton}

@Singleton
private[finatra] class JsonStreamParser @Inject()(
  mapper: FinatraObjectMapper) {

  def parseArray[T: Manifest](reader: Reader): AsyncStream[T] = {
    val bufs = AsyncStream.fromReader(reader)
    parseArray[T](bufs)
  }

  def parseArray[T: Manifest](bufs: AsyncStream[Buf]): AsyncStream[T] = {
    val jsonDecoder = new JsonArrayChunker()
    for {
      buf <- bufs
      jsonArrayDelimitedBuf <- AsyncStream.fromSeq(jsonDecoder.decode(buf))
      parsedElem = mapper.parse[T](jsonArrayDelimitedBuf)
    } yield parsedElem
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy