/// <summary> /// Loads a RDF Dataset from the NQuads input using a RDF Handler /// </summary> /// <param name="handler">RDF Handler to use</param> /// <param name="input">Input to load from</param> public void Load(IRdfHandler handler, TextReader input) { if (handler == null) { throw new RdfParseException("Cannot parse an RDF Dataset using a null handler"); } if (input == null) { throw new RdfParseException("Cannot parse an RDF Dataset from a null input"); } try { //Setup Token Queue and Tokeniser NTriplesTokeniser tokeniser = new NTriplesTokeniser(input); tokeniser.NQuadsMode = true; ITokenQueue tokens; switch (this._queueMode) { case TokenQueueMode.AsynchronousBufferDuringParsing: tokens = new AsynchronousBufferedTokenQueue(tokeniser); break; case TokenQueueMode.QueueAllBeforeParsing: tokens = new TokenQueue(tokeniser); break; case TokenQueueMode.SynchronousBufferDuringParsing: default: tokens = new BufferedTokenQueue(tokeniser); break; } tokens.Tracing = this._tracetokeniser; tokens.InitialiseBuffer(); //Invoke the Parser this.Parse(handler, tokens); } catch { throw; } finally { try { input.Close(); } catch { //No catch actions - just cleaning up } } }
/// <summary> /// Loads a RDF Dataset from the NQuads input using a RDF Handler /// </summary> /// <param name="handler">RDF Handler to use</param> /// <param name="input">Input to load from</param> public void Load(IRdfHandler handler, TextReader input) { if (handler == null) { throw new RdfParseException("Cannot parse an RDF Dataset using a null handler"); } if (input == null) { throw new RdfParseException("Cannot parse an RDF Dataset from a null input"); } // Check for incorrect stream encoding and issue warning if appropriate if (input is StreamReader) { switch (this.Syntax) { case NQuadsSyntax.Original: #if !SILVERLIGHT //Issue a Warning if the Encoding of the Stream is not ASCII if (!((StreamReader)input).CurrentEncoding.Equals(Encoding.ASCII)) { this.RaiseWarning("Expected Input Stream to be encoded as ASCII but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.EncodingName + " - Please be aware that parsing errors may occur as a result"); } #endif break; default: if (!((StreamReader)input).CurrentEncoding.Equals(Encoding.UTF8)) { #if SILVERLIGHT this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.GetType().Name + " - Please be aware that parsing errors may occur as a result"); #else this.RaiseWarning("Expected Input Stream to be encoded as UTF-8 but got a Stream encoded as " + ((StreamReader)input).CurrentEncoding.EncodingName + " - Please be aware that parsing errors may occur as a result"); #endif } break; } } try { //Setup Token Queue and Tokeniser NTriplesTokeniser tokeniser = new NTriplesTokeniser(input, AsNTriplesSyntax(this.Syntax)); tokeniser.NQuadsMode = true; ITokenQueue tokens; switch (this.TokenQueueMode) { case TokenQueueMode.AsynchronousBufferDuringParsing: tokens = new AsynchronousBufferedTokenQueue(tokeniser); break; case TokenQueueMode.QueueAllBeforeParsing: tokens = new TokenQueue(tokeniser); break; case TokenQueueMode.SynchronousBufferDuringParsing: default: tokens = new BufferedTokenQueue(tokeniser); break; } tokens.Tracing = this.TraceTokeniser; tokens.InitialiseBuffer(); //Invoke the Parser this.Parse(handler, tokens); } catch { throw; } finally { try { input.Close(); } catch { //No catch actions - just cleaning up } } }