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

com.twitter.finatra.json.internal.streaming.ByteBufferUtils.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.finatra.conversions.buf._
import com.twitter.inject.Logging
import com.twitter.io.Buf
import java.nio.ByteBuffer

private[finatra] object ByteBufferUtils extends Logging {

  //TODO: Optimize/Refactor
  def append(byteBuffer: ByteBuffer, buf: Buf): ByteBuffer = {
    val byteBufferBuf = {
      val byteBufferCopy = byteBuffer.duplicate()
      byteBufferCopy.position(0)
      Buf.ByteBuffer.Shared(byteBufferCopy)
    }

    val combinedBufs = byteBufferBuf.concat(buf)
    Buf.ByteBuffer.Shared.extract(combinedBufs)
  }

  def debugBuffer(byteBuffer: ByteBuffer) = {
    val copy = byteBuffer.duplicate()
    copy.position(0)
    val buf = Buf.ByteBuffer.Shared(copy)
    val str = buf.utf8str

    debug(s"byteBuffer: $str pos: ${byteBuffer.position }")
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy