{@inheritdoc}

@param $stream
@return bool
160546
public function hasStream($stream)
    {
        $isInputStream = $stream == $this->getInputStream();
        $isOutputStream = $stream == $this->getOutputStream();
        $isErrStream = $stream == $this->getErrorStream();

        return $isInputStream || $isOutputStream || $isErrStream;
    }
453124
public function copy($stream)
    {
        if($this->getResource())
        {
            if (!$stream instanceof KFilesystemStreamInterface && !is_resource($stream) && !get_resource_type($stream) == 'stream')
            {
                throw new InvalidArgumentException(sprintf(
                    'Stream must be on object implementing the FilesystemStreamInterface or a resource of type "stream".'
                ));
            }

            if($stream instanceof KFilesystemStreamInterface) {
                $resource = $stream->getResource();
            } else {
                $resource = $stream;
            }

            return fwrite($resource, $this->read());
        }

        return false;
    }
766534
public function setStream($stream, bool $closeStream = false)
    {
        $meta = @stream_get_meta_data($stream);
        if (!$meta || !$meta['mode'] || $meta['mode'][0] != 'r' || $meta['eof']) {
            throw new NonReadableStreamException();
        }

        $text = '';
        while (!feof($stream)) {
            $text .= fread($stream, 2082);
        }

        if ($closeStream) {
            fclose($stream);
        }

        return $this->setText($text);
    }
229263
public function readByteStream(Stream $stream)
    {
        $length = $this->readVarint($stream);
        $value  = $stream->readStream($length);

        return $value;
    }
510626
public function initFromStream($stream)
    {
        $stream = Factory::stream($stream);

        try {
            $offset = $stream->tell();
        } catch (\RuntimeException $e) {
            $offset = 0;
        }

        $shouldAndCanSeek = $offset !== 0 && $stream->isSeekable();

        if ($shouldAndCanSeek) {
            $stream->rewind();
        }

        try {
            $data = $stream->getContents();
        } catch (\RuntimeException $e) {
            $data = null;
        }

        if ($shouldAndCanSeek) {
            $stream->seek($offset);
        }

        if ($data) {
            return $this->initFromBinary($data);
        }

        throw new Exception\NotReadableException(
            "Unable to init from given stream"
        );
    }
925844
public function readByte(Stream $stream)
    {
        $char = $stream->read(1);
        $byte = ord($char);

        return $byte;
    }
1093684
public function readSFixed64(Stream $stream)
    {
        $bytes = $stream->read(8);

        list(, $lo0, $lo1, $hi0, $hi1) = unpack('v*', $bytes);

        return ($hi1 << 16 | $hi0) << 32 | ($lo1 << 16 | $lo0);
    }
746794
private function parseArgumentList(Stream $stream)
    {
        $arguments = [];

        do {
            $argument = $stream->expects(Token::TYPE_IDENTIFIER)->getValue();

            $stream->expects(Token::TYPE_SYMBOL, ':');

            if ($stream->current()->equals(Token::TYPE_SYMBOL, '#')) {
                $type = $this->parseFragmentTypeAlias($stream);
            } else {
                $type = $this->parseTypeAlias($stream);
            }

            $argument = [
                'argument' => $argument,
                'type' => $type,
            ];

            if ($stream->current()->equals(Token::TYPE_SYMBOL, '=')) {
                $stream->expects(Token::TYPE_SYMBOL, '=');

                $argument['default'] = $this->parseValue($stream);
            }

            $arguments[] = $argument;
        } while ($stream->current()->equals(Token::TYPE_SYMBOL, ',') && $stream->expects(Token::TYPE_SYMBOL, ','));

        return $arguments;
    }
382718
public function readSFixed32(Stream $stream)
    {
        $bytes = $stream->read(4);

        if ($this->isBigEndian) {
            $bytes = strrev($bytes);
        }

        list(, $result) = unpack('l', $bytes);

        return $result;
    }
1144131
public function addStream($stream)
    {
        while (!feof($stream)) {
            $freeBufferLength = $this->chunkSize - StringHelper::byteLength($this->_buffer);

            $streamChunk = fread($stream, $freeBufferLength);
            if ($streamChunk === false) {
                break;
            }
            $this->_buffer .= $streamChunk;
            $this->flushBuffer();
        }

        return $this;
    }
672816
private function parseFragmentTypeAlias(Stream $stream)
    {
        $alias = $stream->expects(Token::TYPE_SYMBOL, '#')->getValue();

        while ($stream->current()->equals(Token::TYPE_SYMBOL, '[')) {
            $stream->expects(Token::TYPE_SYMBOL, '[');
            $stream->expects(Token::TYPE_SYMBOL, ']');

            $alias = sprintf('%s[]', $alias);
        }

        return $alias;
    }
140165
public function stream_write($data) {
    assert(isset($this->client));
    return $this->client->write($data);
  }
337919
public function readZigzag(Stream $stream)
    {
        $number = $this->readVarint($stream);
        $zigzag = ($number >> 1) ^ (-($number & 1));

        return $zigzag;
    }
1079815
public static function getStreamExt($stream)
    {
        if (is_file(pathinfo($stream, PATHINFO_DIRNAME)) && is_readable($stream)) {
            $stream = file_get_contents($stream);
        }

        $finfo = new finfo(FILEINFO_MIME);

        $mime = strstr($finfo->buffer($stream), ';', true);

        return isset(self::$extensionMap[$mime]) ? self::$extensionMap[$mime] : self::getExtBySignature($stream);
    }
789323
public function read(AbstractStream $stream)
    {
        return $stream->getBuffer()->read($this->getSize(), $this->getEndian());
    }
1006582
public function parse(AbstractStream $stream)
    {
        try {
            return parent::parse($stream);
        } catch (\OutOfBoundsException $e) {
            if ($this->isUntilEof()) {
                return $this->dataSet->getData();
            }

            throw $e;
        }
    }
1270966
public function startRecording($stream)
    {
        $parts = explode('/', $this->streamserver_config[$stream->getRtmpServer()]['rtmp_url']);
        $rtmp_app = end($parts);
        $success = $this->record(
            $this->streamserver_config[$stream->getRtmpServer()]['rtmp_control'],
            $rtmp_app,
            $stream->getUniqID()
        );
        if ($success) {
            $stream->setTechnicalStatus(Stream::STATE_RECORDING);
            $this->em->persist($stream);
            $this->em->flush();

            $event = new StartRecordingStreamEvent($stream);
            $this->dispatcher->dispatch(
                OktolabMediaEvent::STREAM_START_RECORDING,
                $event
            );
            return true;
        }
        return false;
    }