public void Write() { Stream stream = StringToMemoryStreamBuilder.Builder(Encoding.UTF8).WriteLine("line1").WriteLine("line2").WriteLine("line3").Done(); VisitingLines visitor = new VisitingLines(); StreamToLines streamToLines = new StreamToLines(visitor, Encoding.UTF8); streamToLines.ReadFrom(stream); visitor.NoEmptyLines().Lines(3).Line(0, "line1").Line(1, "line2").Line(2, "line3"); }
public void Read() { Stream stream = NewStream(); List <String> lines = new List <String> (); VisitingLines visitor = new VisitingLines(lines); new LineReader(Encoding.UTF8).Read(stream, visitor); Assert.IsFalse(visitor.EmptyLinesDetected()); Assert.AreEqual(2, visitor.Lines.Count); Assert.IsTrue(visitor.Lines.Contains("line1")); Assert.IsTrue(visitor.Lines.Contains("line2")); }
public void ReadStream() { Stream stream = StringToMemoryStreamBuilder.Builder(Encoding.UTF8).WriteLine("line1").WriteLine("line2").Done(); Console.WriteLine("uncompressed stream length= " + stream.Length); var memoryStream = new MemoryStream(); var gZipStream = new GZipStream(memoryStream, CompressionMode.Compress); stream.CopyTo(gZipStream); gZipStream.Flush(); memoryStream.Position = 0; Console.WriteLine("compressed stream length= " + memoryStream.Length); var visitingLines = new VisitingLines(); var compressed = new MemoryStream(memoryStream.ToArray()); Console.WriteLine("(copied) compressed stream length= " + compressed.Length); new GZipStreamToLines(visitingLines, Encoding.UTF8).ReadFrom(memoryStream); visitingLines.NoEmptyLines().Lines(2).Line(0, "line1").Line(1, "line2"); }
public void ReadEmptyLines() { MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream, Encoding.UTF8); writer.Write("line1"); writer.WriteLine(); writer.WriteLine(); writer.Write("line2"); writer.WriteLine(); writer.Flush(); stream.Position = 0; List <String> lines = new List <String> (); VisitingLines visitor = new VisitingLines(lines); new LineReader(Encoding.UTF8).Read(stream, visitor); Assert.IsTrue(visitor.EmptyLinesDetected()); Assert.AreEqual(2, visitor.Lines.Count); Assert.IsTrue(visitor.Lines.Contains("line1")); Assert.IsTrue(visitor.Lines.Contains("line2")); Assert.AreEqual(1, visitor.EmptyLines.Count); }