public void ParsingTextReaderBlockingComplexReadBlock3() { StringReader strReader = new StringReader(TestData); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader, 2); char[] cs = new char[10]; int start = 0; while (!reader.EndOfStream) { int read = reader.ReadBlock(cs, 0, cs.Length); Assert.IsTrue(read <= 10); if (read == 0) { break; } String s = new string(cs, 0, read); Assert.AreEqual(TestData.Substring(start, read), s); start += 10; } Assert.IsTrue(reader.EndOfStream); Assert.AreEqual(-1, reader.Peek()); Assert.AreEqual(-1, reader.Read()); reader.Close(); }
public void ParsingBlockingVsNonBlocking5() { this.EnsureNIOData(); Stopwatch timer = new Stopwatch(); TimeSpan blockingTime = new TimeSpan(), nonBlockingTime = new TimeSpan(); for (int i = 0; i < 25; i++) { Console.WriteLine("Run #" + (i + 1)); timer.Reset(); //Test Blocking BlockingTextReader blocking = ParsingTextReader.CreateBlocking(new JitterReader(new StreamReader("resources\\nio.ttl"), 50)); timer.Start(); int totalBlocking = 0; int read; while (!blocking.EndOfStream) { read = blocking.Read(); if (read >= 0) { totalBlocking++; } } timer.Stop(); blocking.Close(); blockingTime = blockingTime.Add(timer.Elapsed); Console.WriteLine("Blocking IO took " + timer.Elapsed + " and read " + totalBlocking + " characters"); //Reset timer.Reset(); int totalNonBlocking = 0; NonBlockingTextReader nonBlocking = ParsingTextReader.CreateNonBlocking(new JitterReader(new StreamReader("resources\\nio.ttl"), 50)); timer.Start(); while (!nonBlocking.EndOfStream) { read = nonBlocking.Read(); if (read >= 0) { totalNonBlocking++; } } timer.Stop(); nonBlocking.Close(); nonBlockingTime = nonBlockingTime.Add(timer.Elapsed); Console.WriteLine("Non-Blocking IO took " + timer.Elapsed + " and read " + totalNonBlocking + " characters"); Assert.AreEqual(totalBlocking, totalNonBlocking); } Console.WriteLine(); Console.WriteLine("Blocking Total Time = " + blockingTime); Console.WriteLine("Non-Blocking Total Time = " + nonBlockingTime); }
public void ParsingTextReaderCreation2() { using (MemoryStream stream = new MemoryStream()) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsInstanceOf <NonBlockingTextReader>(reader); stream.Close(); } }
public void ParsingTextReaderCreation1() { File.WriteAllText("ParsingTextReaderCreation1.txt", "ParsingTextReaderCreation1"); using (StreamReader stream = File.OpenText("ParsingTextReaderCreation1.txt")) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsType <NonBlockingTextReader>(reader); stream.Close(); } }
public void ParsingTextReaderCreation1() { File.WriteAllText("ParsingTextReaderCreation1.txt", "ParsingTextReaderCreation1"); using (StreamReader stream = new StreamReader("ParsingTextReaderCreation1.txt")) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsInstanceOfType(reader, typeof(NonBlockingTextReader)); stream.Close(); } }
public void ParsingTextReaderCreation3() { using (WebClient client = new WebClient()) { using (Stream stream = client.OpenRead(new Uri("http://www.dotnetrdf.org"))) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsInstanceOf <BlockingTextReader>(reader); stream.Close(); } client.Dispose(); } }
public void ParsingTextReaderBlockingReadLine() { StringReader strReader = new StringReader(TestData); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader); String s = reader.ReadLine(); Assert.AreEqual(TestData, s); Assert.AreEqual(-1, reader.Peek()); Assert.AreEqual(-1, reader.Read()); reader.Close(); }
public void ParsingTextReaderCreation3() { using (WebClient client = new WebClient()) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; using (Stream stream = client.OpenRead(new Uri("http://www.dotnetrdf.org"))) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsType <BlockingTextReader>(reader); stream.Close(); } client.Dispose(); } }
public void ParsingTextReaderCreation1() { File.WriteAllText("ParsingTextReaderCreation1.txt", "ParsingTextReaderCreation1"); using (StreamReader stream = new StreamReader("ParsingTextReaderCreation1.txt")) { ParsingTextReader reader = ParsingTextReader.Create(stream); #if PORTABLE // Portable class library uses blocking IO for file streams Assert.IsInstanceOf <BlockingTextReader>(reader); #else Assert.IsInstanceOf <NonBlockingTextReader>(reader); #endif stream.Close(); } }
public void ParsingTextReaderBlockingReadLine5() { StringReader strReader = new StringReader(TestData5); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader); String s = reader.ReadLine(); Assert.Equal(TestData5.Substring(0, 26), s); s = reader.ReadLine(); Assert.Equal(TestData5.Substring(28), s); Assert.Equal(-1, reader.Peek()); Assert.Equal(-1, reader.Read()); reader.Close(); }
public void ParsingTextReaderBlockingSimplePeek() { StringReader strReader = new StringReader(TestData); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader); for (int i = 1; i <= 100; i++) { char c = (char)reader.Peek(); Console.WriteLine("Peek #" + i + " = " + c); Assert.AreEqual(TestData[0], c); } Assert.IsFalse(reader.EndOfStream); Assert.AreNotEqual(-1, reader.Peek()); Assert.AreNotEqual(-1, reader.Read()); reader.Close(); }
public void ParsingTextReaderCreation5() { try { Options.ForceBlockingIO = true; using (MemoryStream stream = new MemoryStream()) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsInstanceOf <BlockingTextReader>(reader); stream.Close(); } } finally { Options.ForceBlockingIO = false; } }
public void ParsingTextReaderCreation4() { try { Options.ForceBlockingIO = true; File.WriteAllText("ParsingTextReaderCreation4.txt", "ParsingTextReaderCreation1"); using (StreamReader stream = new StreamReader("ParsingTextReaderCreation4.txt")) { ParsingTextReader reader = ParsingTextReader.Create(stream); Assert.IsInstanceOf <BlockingTextReader>(reader); stream.Close(); } } finally { Options.ForceBlockingIO = false; } }
public void ParsingTextReaderBlockingSimpleReadBlock() { StringReader strReader = new StringReader(TestData); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader); char[] cs = new char[100]; int read = reader.ReadBlock(cs, 0, cs.Length); Assert.AreEqual(TestData.Length, read); Assert.IsTrue(reader.EndOfStream); Assert.AreEqual(-1, reader.Peek()); Assert.AreEqual(-1, reader.Read()); reader.Close(); String s = new string(cs, 0, read); Assert.AreEqual(TestData, s); }
public void ParsingTextReaderBlockingSimpleRead() { StringReader strReader = new StringReader(TestData); BlockingTextReader reader = ParsingTextReader.CreateBlocking(strReader); StringBuilder output = new StringBuilder(); while (!reader.EndOfStream) { output.Append((char)reader.Read()); } Assert.IsTrue(reader.EndOfStream); Assert.AreEqual(-1, reader.Peek()); Assert.AreEqual(-1, reader.Read()); reader.Close(); Console.WriteLine(output.ToString()); Assert.AreEqual(TestData, output.ToString()); }
public void ParsingTextReaderBlockingBadInstantiation2() { BlockingTextReader reader = ParsingTextReader.CreateBlocking(new StringReader(String.Empty), 0); }
public CommentIgnoringJsonTextReader(ParsingTextReader reader) : base(reader) { }
private CommentIgnoringJsonTextReader(ParsingTextReader reader) : base(reader) { DateParseHandling = DateParseHandling.None; }
public void ParsingBlockingVsNonBlocking3() { this.EnsureNIOData(); Stopwatch timer = new Stopwatch(); TimeSpan blockingTime = new TimeSpan(), nonBlockingTime = new TimeSpan(); int maxSize = 1024 * 32; for (int size = 1024; size < maxSize; size += 1024) { Console.WriteLine("Buffer Size " + size); for (int i = 0; i < 25; i++) { timer.Reset(); //Test Blocking BlockingTextReader blocking = ParsingTextReader.CreateBlocking(new StreamReader("resources\\nio.ttl"), 4096); timer.Start(); int totalBlocking = 0; int read; while (!blocking.EndOfStream) { read = blocking.Read(); if (read >= 0) { totalBlocking++; } } timer.Stop(); blocking.Close(); blockingTime = blockingTime.Add(timer.Elapsed); //Reset timer.Reset(); int totalNonBlocking = 0; NonBlockingTextReader nonBlocking = ParsingTextReader.CreateNonBlocking(new StreamReader("resources\\nio.ttl"), 4096); timer.Start(); while (!nonBlocking.EndOfStream) { read = nonBlocking.Read(); if (read >= 0) { totalNonBlocking++; } } timer.Stop(); nonBlocking.Close(); nonBlockingTime = nonBlockingTime.Add(timer.Elapsed); Assert.AreEqual(totalBlocking, totalNonBlocking); } Console.WriteLine(); Console.WriteLine("Blocking Total Time = " + blockingTime); Console.WriteLine("Non-Blocking Total Time = " + nonBlockingTime); Console.WriteLine(); blockingTime = new TimeSpan(); nonBlockingTime = new TimeSpan(); } }
public CommentIgnoringJsonTextReader(TextReader reader) : this(ParsingTextReader.Create(reader)) { }
public void ParsingTextReaderBlockingBadInstantiation() { Assert.Throws <ArgumentNullException>(() => ParsingTextReader.CreateBlocking((TextReader)null)); }
public void ParsingTextReaderBlockingBadInstantiation2() { Assert.Throws <ArgumentException>(() => ParsingTextReader.CreateBlocking(new StringReader(String.Empty), 0)); }
/// <summary> /// Loads a Result Set from an Input using a Results Handler. /// </summary> /// <param name="handler">Results Handler to use.</param> /// <param name="input">Input to read from.</param> public void Load(ISparqlResultsHandler handler, TextReader input) { if (handler == null) { throw new RdfParseException("Cannot parse SPARQL Results into a null Result Handler"); } if (input == null) { throw new RdfParseException("Cannot parse SPARQL Results from a null input stream"); } try { TokenisingResultParserContext context = new TokenisingResultParserContext(handler, new TsvTokeniser(ParsingTextReader.Create(input))); TryParseResults(context); input.Close(); } catch { try { input.Close(); } catch { // No catch actions just trying to clean up } throw; } }
public void ParsingTextReaderBlockingBadInstantiation() { BlockingTextReader reader = ParsingTextReader.CreateBlocking((TextReader)null); }