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);
    }