Implementing the `seek()` method of the `Seekable` interface

@throws \OutOfBoundsException if the provided position doesn't exist
@return void
340145
public function seek($position)
    {
        $this->rewind();
        for ($i=0; $i<$position; $i++) {
            $this->next();
        }
        if (!$this->valid()) {
            throw new \OutOfBoundsException(
                sprintf('Invalid seek position "%s"!', $position)
            );
        }
    }
1299742
public function seek($position)
    {
        $position = (int) $position;
        if ($position < 0 || $position >= $this->_count) {
            // require_once 'Zend/Db/Table/Rowset/Exception.php';
            throw new Zend_Db_Table_Rowset_Exception("Illegal index $position");
        }
        $this->_pointer = $position;
        return $this;
    }
590855
def seek(self, offset):
        
        if self._shifts:
            if 0 <= offset < len(self._shifts):
                current_pos = self._file.tell()
                new_pos = self._shifts[offset]
                if current_pos != new_pos:
                    if current_pos == self._shifts[-1]:  # reached the end of the file
                        self._data = self.__reader()
                        self.__file = iter(self._file.readline, '')
                    self._file.seek(new_pos)
            else:
                raise IndexError('invalid offset')
        else:
            raise self._implement_error
384146
public void seek(long pos) throws IOException {

		int n = (int) (real_pos - pos);

		if (n >= 0 && n <= buf_end) {

			buf_pos = buf_end - n;

		} else {

			raf.seek(pos);

			buf_end = 0;
			buf_pos = 0;
			real_pos = raf.getFilePointer();
		}
	}
1176462
public function seek($offset, $whence = SEEK_SET)
    {
        if ($whence !== SEEK_SET || $offset < 0) {
            throw new RuntimeException(sprintf(
                'Cannot seek to offset % with whence %s',
                $offset,
                $whence
            ));
        }

        $offset += $this->offset;

        if ($this->limit !== -1) {
            if ($offset > $this->offset + $this->limit) {
                $offset = $this->offset + $this->limit;
            }
        }

        $this->stream->seek($offset);
    }
685527
public function at($index)
    {
        if (isset($this->_children[$index])) {
            return $this->_children[$index];
        }
        throw new OutOfBoundsException("Index $index does not exist");
    }
184498
public function rewind()
    {
        if (!($this->inputStream instanceof Seekable)) {
            return;
        }

        $this->inputStream->seek(0, Seekable::SET);
        $this->lineNumber  = 0;
        $this->currentLine = null;
        $this->next();
    }
1129796
def seek(self, offset, whence=START):
        """"""
        logger.debug('seeking to offset: %r whence: %r', offset, whence)
        if whence not in WHENCE_CHOICES:
            raise ValueError('invalid whence, expected one of %r' % WHENCE_CHOICES)

        if whence == START:
            new_position = offset
        elif whence == CURRENT:
            new_position = self._current_pos + offset
        else:
            new_position = self._content_length + offset
        new_position = clamp(new_position, 0, self._content_length)
        self._current_pos = new_position
        self._raw_reader.seek(new_position)
        logger.debug('new_position: %r', self._current_pos)

        self._buffer.empty()
        self._eof = self._current_pos == self._content_length
        return self._current_pos
68927
public function offsetGet($position)
    {
        if (!isset($this->errors[$position])) {
            throw new OutOfBoundsException('The offset '.$position.' does not exist.');
        }

        return $this->errors[$position];
    }
1245888
private function getOutOfBoundsException($position = null)
    {
        return new OutOfBoundsException(
            sprintf('Invalid token position (%d)', $position !== null ? $position : $this->position)
        );
    }
749146
public function seek($position)
    {
        if ($position < 0) {
            throw new \OutOfBoundsException("Unable to seek to negative offset $position");
        }

        if ($this->_position !== $position) {
            if(($count = $this->_result->num_rows) && ($position > ($count-1)))
                throw new \OutOfBoundsException("Unable to seek to offset $position");

            if ($count) {
                $this->_result->data_seek($this->_position = $position);
                $this->_currentRow = $this->_fetch();
            }

            $this->_position = $position;
        }
    }
420982
public function setOffset($offset)
    {
        if ($offset > $this->bufferLength || $offset < 0) {
            throw new \OutOfRangeException(
                \sprintf('Offset (%s) out of range (length: %s)', $offset, $this->bufferLength)
            );
        }

        $this->offset = (int) $offset;
    }
1163494
protected void validatePosition(long position) throws IOException {
    if (position < 0) {
      throw new EOFException(
          String.format(
              "Invalid seek offset: position value (%d) must be >= 0 for '%s'",
              position, resourceIdString));
    }

    if (size >= 0 && position >= size) {
      throw new EOFException(
          String.format(
              "Invalid seek offset: position value (%d) must be between 0 and %d for '%s'",
              position, size, resourceIdString));
    }
  }
1247480
private function findOffset()
    {
        $this->seek(0);

        $offset = 0;

        while (!$this->isEndOfFile()) {
            if (strtolower($this->read(1)) === self::$sequence[$offset]) {
                $offset++;
            } else {
                $offset = 0;
            }

            if (!isset(self::$sequence[$offset + 1])) {
                break;
            }
        }

        $this->seek(1, SEEK_CUR);

        if ($offset === (count(self::$sequence) - 1)) {
            $position = $this->getPosition();

            if ("\r\n" === $this->read(2)) {
                return $position + 2;
            }

            return $position;
        }

        return null;
    }
383949
public function rewind() : void
	{
		if (! \is_resource($this->resource))
		{
			throw new Exception\UnseekableStreamException('Stream is not resourceable');
		}

		if (! $this->isSeekable())
		{
			throw new Exception\UnseekableStreamException('Stream is not seekable');
		}

		$result = \fseek($this->resource, 0, \SEEK_SET);

		if (! (0 === $result))
		{
			throw new Exception\UnseekableStreamException('Unable to move the stream pointer to beginning');
		}
	}
286664
public function setOffset($offset)
    {
        $current = $this->stream->tell();

        if ($current !== $offset) {
            // If the stream cannot seek to the offset position, then read to it
            if ($this->stream->isSeekable()) {
                $this->stream->seek($offset);
            } elseif ($current > $offset) {
                throw new \RuntimeException("Could not seek to stream offset $offset");
            } else {
                $this->stream->read($offset - $current);
            }
        }

        $this->offset = $offset;
    }
1302175
public function remove($offset, $length = 1)
    {
        if (!isset($this->elements[$offset])) {
            throw new OutOfBoundsException(sprintf('The offset %s is not within the property path', $offset));
        }

        $this->resize($offset, $length, 0);
    }