@param resource $stream

@return $this
@throws NonReadableStreamException
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);
    }
155537
public function compile(Stream $stream)
    {
        // Parse the request
        $request    = CodeGeneratorRequest::fromStream($stream, $this->config);
        $response   = new CodeGeneratorResponse();
        $context    = $this->createContext($request);
        $entities   = $context->getEntities();
        $options    = $context->getOptions();
        $generator  = new Generator($context);

        // whether or not it will renegerate classes with new extensions
        $regenerate   = false;
        $hasExtension = $context->hasProtobufExtension();

        // Run each entity
        foreach ($entities as $key => $entity) {
            $generateImported = $options->getGenerateImported();
            $isFileToGenerate = $entity->isFileToGenerate();

            // Only compile those given to generate, not the imported ones
            if ( ! $generateImported && ! $isFileToGenerate) {
                $this->logger->debug(sprintf('Skipping generation of imported class "%s"', $entity->getClass()));

                continue;
            }

            $this->logger->info(sprintf('Generating class "%s"', $entity->getClass()));

            $generator->visit($entity);

            $file    = new File();
            $path    = $entity->getPath();
            $content = $entity->getContent();

            $file->setName($path);
            $file->setContent($content);

            $response->addFile($file);

            if ($hasExtension && $this->loadEntityClass($entity)) {
                $regenerate = true;
            }
        }

        if ($regenerate) {

            $this->logger->info('Regenerating classes with new extensions');

            $stream->seek(0);

            // Renegerate classes with new extensions
            return $this->compile($stream);
        }

        $this->logger->info('Generation completed.');

        // Finally serialize the response object
        return $response->toStream($this->config);
    }
641703
public function parse(NodeStream $stream)
    {
        $builder = new ClassBuilder();

        while (!$stream->is(TokenParser::NODE_EON)) {
            switch ($this->status) {
                case self::STAT_NONE:
                    $this->parseClass($builder, $stream);
                    break;
                case self::STAT_BODY:
                    $methodNodes = array(
                        TokenParser::NODE_PUBLIC_METHOD,
                        TokenParser::NODE_PROTECTED_METHOD,
                        TokenParser::NODE_PRIVATE_METHOD
                    );
                    if ($stream->is($methodNodes)) {
                        $this->parseMethod($builder, $stream);
                    } else {
                        $this->parseProperty($builder, $stream);
                    }
                    break;
                default:
                    $stream->next();
                    break;
            }
        }

        return $builder;
    }
1099692
public static function getResource(StreamInterface $stream)
    {
        $mode = null;
        if ($stream->isReadable()) {
            $mode = 'r';
        }

        if ($stream->isWritable()) {
            $mode = !empty($mode) ? 'r+' : 'w';
        }

        if (empty($mode)) {
            throw new WrapperException("Stream is not available in read or write modes");
        }

        return fopen(self::localFilename($stream), $mode);
    }
1107668
protected function setStream(IStream $stream)
    {
        if ($stream->isOpen() === false) {
            $msg = "A BinaryStreamAccess do not accept closed streams to be read.";
            throw new BinaryStreamAccessException($msg, $this, StreamAccessException::NOT_OPEN);
        }

       parent::setStream($stream);
    }
775336
protected function attach($stream)
    {
        if (is_resource($stream) === false) {
            throw new InvalidArgumentException(__METHOD__ . ' argument must be a valid PHP resource');
        }

        if (is_resource($this->stream) === true) {
            $this->detach();
        }

        $this->stream = $stream;
    }
1007621
public function getRaw($stream = false)
    {
        $this->setTokenValue($this->getEntityIdName(), $this->getId());
        $uri = $this->getURI('/raw');
        $x   = $this->getSDK()->get($uri, array(), array('accept'=>'audio/*',
            'content_type'=>'audio/*', 'Range'=> 'bytes'));

        header('Content-Type: '.$x->getHeader('Content-Type')[0]);
        header('content-length: '.$x->getHeader('content-length')[0]);
        header('Accept-Ranges: '.$x->getHeader('Accept-Ranges')[0]);

        if (!$stream) {
            header('Content-Disposition: '.$x->getHeader('Content-Disposition')[0]);
        }
        echo $x->getBody();
    }
1043532
protected function setStream($type, StreamInterface $stream)
    {
        $this->streams[$type] = $stream;

        $callback = array($this, 'on'.ucfirst($type).'Message');

        $stream->addListener(
            StreamInterface::MESSAGE,
            $this->createEventListenerForStream($callback)
        );

        return $this;
    }
840749
public function parse(AbstractStream $stream)
    {
        $value = $this->format($this->read($stream));
        $this->validate($value);
        return $value;
    }
340026
public static function getResource(StreamInterface $stream)
    {
        self::register();

        if ($stream->isReadable()) {
            $mode = $stream->isWritable() ? 'r+' : 'r';
        } elseif ($stream->isWritable()) {
            $mode = 'w';
        } else {
            throw new \InvalidArgumentException('The stream must be readable, '
                .'writable, or both.');
        }

        return fopen('phmessage://stream', $mode, null, stream_context_create([
            'phmessage' => ['stream' => $stream],
        ]));
    }
1177930
public function seek(int $offset): StreamInterface
    {
        if ( ! is_resource($this->stream) ) {
            throw new StreamException('Stream is not longer available');
        }

        if ( ! $this->seekable ) {
            throw new StreamException('Stream is not seekable');
        }

        $position = fseek($this->stream, $offset, SEEK_SET);

        if ( $position === -1 ) {
            throw new StreamException('Unable to seek to stream position');
        }

        return $this;
    }
640367
function fromResource($value)
    {
        $this->clear();
        $this->orignalValue = $this->returnValue  = stream_get_contents($value);
        return $this->parse();
    }
632332
public static function fromStream(StreamInterface $stream)
    {
        if (! $stream->isReadable() || ! $stream->isSeekable()) {
            throw new InvalidArgumentException('Message stream must be both readable and seekable');
        }

        $stream->rewind();

        list($method, $requestTarget, $version) = self::getRequestLine($stream);
        $uri = self::createUriFromRequestTarget($requestTarget);

        list($headers, $body) = self::splitStream($stream);

        return (new Request($uri, $method, $body, $headers))
            ->withProtocolVersion($version)
            ->withRequestTarget($requestTarget);
    }
128498
public function commit(EventStream $stream)
    {
        $newEvents = $stream->newEvents();

        if (count($newEvents) === 0) {
            return new Transaction($stream, $newEvents);
        }

        $id = (string)$stream->getUuid();
        $currentVersion = $stream->getVersion();
        $nextVersion = $currentVersion + count($newEvents);

        $eventData = isset($this->eventsData[$id])
            ? $this->eventsData[$id]
            : array();

        foreach ($newEvents as $newEvent) {
            $eventData[] = $this->serializer->toArray($newEvent);
        }

        $this->storage->store($id, $stream->getClassName(), $eventData, $nextVersion, $currentVersion);

        $stream->markNewEventsProcessed($nextVersion);

        return new Transaction($stream, $newEvents);
    }
583923
public function addStream(IStream $stream) : void
    {
        if (!$stream->isReadable()) {
            throw new InvalidArgumentException('Stream must be readable');
        }

        $this->isSeekable = $this->isSeekable && $stream->isSeekable();
        $this->streams[] = $stream;
    }
100406
public static ResourceMeta withStream(final HasInputStream stream, final Map<String, String> meta) {
        return new BaseStreamResource(meta,stream);
    }
179718
public function parse(TokenStream $stream) : RootNode
    {
        if (! $this->runtime) {
            throw new AegisError('Runtime needs to be set before parsing');
        }

        $this->prepare($stream);
        $this->parseOutsideTag();

        if ($this->cursor !== $this->lastTokenIndex) {
            $this->syntaxError('Unexpected token ' . $this->getCurrentToken());
        }

        return $this->getRoot();
    }