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

tech.ytsaurus.spyt.fs.YtFsInputStream.scala Maven / Gradle / Ivy

There is a newer version: 2.6.0-alpha-1
Show newest version
package tech.ytsaurus.spyt.fs

import org.apache.hadoop.fs.{FSInputStream, FileSystem}
import tech.ytsaurus.spyt.wrapper.file.YtFileInputStream

import scala.annotation.tailrec

class YtFsInputStream(in: YtFileInputStream, statistics: FileSystem.Statistics) extends FSInputStream {
  @tailrec
  override final def seek(pos: Long): Unit = {
    if (getPos < pos) {
      readInt()
      seek(pos)
    } else if (getPos > pos) {
      throw new UnsupportedOperationException("Backward seek is not supported")
    }
  }

  override def getPos: Long = in.pos

  override def seekToNewSource(targetPos: Long): Boolean = ???

  private def readInt(): Int = {
    if (in.hasNext) in.next() & 0xff else -1
  }

  override def read(): Int = {
    val r = readInt()
    if (r >= 0) {
      statistics.incrementBytesRead(1)
    }
    r
  }

  override def read(b: Array[Byte], off: Int, len: Int): Int = {
    val r = in.read(b, off, len)
    if (r >= 0) {
      statistics.incrementBytesRead(r)
    }
    r
  }

  override def close(): Unit = {
    in.close()
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy