public function serializeIteratorToStream(StatementIterator $statements, $outputStream)
    {
        /*
         * check parameter $outputStream
         */
        if (is_resource($outputStream)) {
            // use it as it is
        } elseif (is_string($outputStream)) {
            $outputStream = fopen($outputStream, 'w');
        } else {
            throw new \Exception('Parameter $outputStream is neither a string nor resource.');
        }

        $graph = new \EasyRdf_Graph();

        // go through all statements
        foreach ($statements as $statement) {
            /*
             * Handle subject
             */
            $stmtSubject = $statement->getSubject();
            if ($stmtSubject->isNamed()) {
                $s = $stmtSubject->getUri();
            } elseif ($stmtSubject->isBlank()) {
                $s = '_:'.$stmtSubject->getBlankId();
            } else {
                throw new \Exception('Subject can either be a blank node or an URI.');
            }

            /*
             * Handle predicate
             */
            $stmtPredicate = $statement->getPredicate();
            if ($stmtPredicate->isNamed()) {
                $p = $stmtPredicate->getUri();
            } else {
                throw new \Exception('Predicate can only be an URI.');
            }

            /*
             * Handle object
             */
            $stmtObject = $statement->getObject();
            if ($stmtObject->isNamed()) {
                $o = ['type' => 'uri', 'value' => $stmtObject->getUri()];
            } elseif ($stmtObject->isBlank()) {
                $o = ['type' => 'bnode', 'value' => '_:'.$stmtObject->getBlankId()];
            } elseif ($stmtObject->isLiteral()) {
                $o = [
                    'type' => 'literal',
                    'value' => $stmtObject->getValue(),
                    'datatype' => $stmtObject->getDataType()->getUri(),
                ];
            } else {
                throw new \Exception('Object can either be a blank node, an URI or literal.');
            }

            $graph->add($s, $p, $o);
        }

        fwrite($outputStream, $graph->serialise($this->serialization).PHP_EOL);
    }
public function serializeIteratorToStream(StatementIterator $statements, $outputStream)
    {
        /*
         * check parameter $outputStream
         */
        if (is_resource($outputStream)) {
            // use it as it is
        } elseif (is_string($outputStream)) {
            $outputStream = fopen($outputStream, 'w');
        } else {
            throw new \Exception('Parameter $outputStream is neither a string nor resource.');
        }

        $graph = new \EasyRdf_Graph();

        // go through all statements
        foreach ($statements as $statement) {
            /*
             * Handle subject
             */
            $stmtSubject = $statement->getSubject();
            if ($stmtSubject->isNamed()) {
                $s = $stmtSubject->getUri();
            } elseif ($stmtSubject->isBlank()) {
                $s = '_:'.$stmtSubject->getBlankId();
            } else {
                throw new \Exception('Subject can either be a blank node or an URI.');
            }

            /*
             * Handle predicate
             */
            $stmtPredicate = $statement->getPredicate();
            if ($stmtPredicate->isNamed()) {
                $p = $stmtPredicate->getUri();
            } else {
                throw new \Exception('Predicate can only be an URI.');
            }

            /*
             * Handle object
             */
            $stmtObject = $statement->getObject();
            if ($stmtObject->isNamed()) {
                $o = ['type' => 'uri', 'value' => $stmtObject->getUri()];
            } elseif ($stmtObject->isBlank()) {
                $o = ['type' => 'bnode', 'value' => '_:'.$stmtObject->getBlankId()];
            } elseif ($stmtObject->isLiteral()) {
                $o = [
                    'type' => 'literal',
                    'value' => $stmtObject->getValue(),
                    'datatype' => $stmtObject->getDataType()->getUri(),
                ];
            } else {
                throw new \Exception('Object can either be a blank node, an URI or literal.');
            }

            $graph->add($s, $p, $o);
        }

        fwrite($outputStream, $graph->serialise($this->serialization).PHP_EOL);
    }
public function serializeIteratorToStream ( StatementIterator $ statements , $ outputStream ) { /*
         * check parameter $outputStream
         */ if ( is_resource ( $ outputStream ) ) { // use it as it is } elseif ( is_string ( $ outputStream ) ) { $ outputStream = fopen ( $ outputStream , 'w' ) ; } else { throw new \ Exception ( 'Parameter $outputStream is neither a string nor resource.' ) ; } $ graph = new \ EasyRdf_Graph ( ) ; // go through all statements foreach ( $ statements as $ statement ) { /*
             * Handle subject
             */ $ stmtSubject = $ statement -> getSubject ( ) ; if ( $ stmtSubject -> isNamed ( ) ) { $ s = $ stmtSubject -> getUri ( ) ; } elseif ( $ stmtSubject -> isBlank ( ) ) { $ s = '_:' . $ stmtSubject -> getBlankId ( ) ; } else { throw new \ Exception ( 'Subject can either be a blank node or an URI.' ) ; } /*
             * Handle predicate
             */ $ stmtPredicate = $ statement -> getPredicate ( ) ; if ( $ stmtPredicate -> isNamed ( ) ) { $ p = $ stmtPredicate -> getUri ( ) ; } else { throw new \ Exception ( 'Predicate can only be an URI.' ) ; } /*
             * Handle object
             */ $ stmtObject = $ statement -> getObject ( ) ; if ( $ stmtObject -> isNamed ( ) ) { $ o = [ 'type' => 'uri' , 'value' => $ stmtObject -> getUri ( ) ] ; } elseif ( $ stmtObject -> isBlank ( ) ) { $ o = [ 'type' => 'bnode' , 'value' => '_:' . $ stmtObject -> getBlankId ( ) ] ; } elseif ( $ stmtObject -> isLiteral ( ) ) { $ o = [ 'type' => 'literal' , 'value' => $ stmtObject -> getValue ( ) , 'datatype' => $ stmtObject -> getDataType ( ) -> getUri ( ) , ] ; } else { throw new \ Exception ( 'Object can either be a blank node, an URI or literal.' ) ; } $ graph -> add ( $ s , $ p , $ o ) ; } fwrite ( $ outputStream , $ graph -> serialise ( $ this -> serialization ) . PHP_EOL ) ; }
Transforms the statements of a StatementIterator instance into a stream, a file for instance.

@param StatementIterator $statements   the StatementIterator containing all the Statements which
should be serialized by the serializer
@param string|resource   $outputStream filename or file pointer to the stream to where the serialization
should be written

@throws \Exception if unknown serilaization was given
Transforms the statements of a StatementIterator instance into a stream a file for instance .