private[finatra] def feedAndParse()

in jackson/src/main/scala/com/twitter/finatra/jackson/streaming/AsyncJsonParser.scala [38:75]


  private[finatra] def feedAndParse(buf: Buf): Seq[Buf] = synchronized {
    assertState()

    buf match {
      case Buf.ByteArray.Owned((bytes, begin, end)) =>
        feeder.feedInput(bytes, begin, end)
      case Buf.ByteArray.Shared(bytes) =>
        feeder.feedInput(bytes, 0, bytes.length)
      case b =>
        val bytes = new Array[Byte](b.length)
        b.write(bytes, 0)
        feeder.feedInput(bytes, 0, bytes.length)
    }

    remaining = ByteBufferUtils.append(remaining, buf, position)
    val result: ListBuffer[Buf] = ListBuffer.empty

    while (parser.nextToken() != JsonToken.NOT_AVAILABLE) {
      updateOpenBrace()
      if (startInitialArray) {
        // exclude the initial `[`
        position = parser.getCurrentLocation.getByteOffset.toInt - offset
      } else if (startObjectArray) {
        // include the starting token of the object or array
        position = parser.getCurrentLocation.getByteOffset.toInt - offset - 1
      } else if (endObjectArray) {
        result += getSlicedBuf
      } else if (endInitialArray) {
        depth = -1
      } else if (depth == 1) {
        result += getSlicedBuf
      } else {
        // fall through expected; a valid JsonToken, such as: FIELD_NAME, VALUE_NUMBER_INT, etc.
      }
    }

    result.toSeq
  }