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

com.zink.scala.fly.stub.ByteBufferInputStream.scala Maven / Gradle / Ivy

package com.zink.scala.fly.stub

import java.io.InputStream
import java.nio.ByteBuffer

class ByteBufferInputStream(byteBuffer:ByteBuffer) extends InputStream {
  
	private var bb:ByteBuffer = _

	switchBuffer(byteBuffer)
 
    def switchBuffer(newByteBuffer:ByteBuffer) {
      synchronized {
        this.bb = newByteBuffer
      }
    }
  
    def read():Int = synchronized {
    	bb.get & 0xFF
    }

    override def read(b:Array[Byte], off:Int, len:Int):Int = synchronized {
	  bb.get(b, off, len)
	  len
    }
    
    override def skip(n:Long):Long = synchronized {
    	bb.position((bb.position() + n).toInt)
    	n
    }

    
    override def available():Int = synchronized { bb.remaining }

    override def markSupported() = true

    override def mark(readAheadLimit:Int) = bb.mark()

    override def reset() {
      synchronized {
        bb.reset()
      }
    }

    /**
     * Doesnt mean anything in this context.
     */
    override def close() {
    }

}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy