static void Main(string[] args) { var sw = new StreamWriter("TestFile.txt"); var nsw = new NumberedTextWriter(sw); nsw.WriteLine("Hello"); nsw.WriteLine("This"); nsw.WriteLine("is"); nsw.WriteLine("a"); nsw.WriteLine("test"); sw.Close(); nsw.Close(); var streamlength = 30; var buf = new Byte[streamlength]; var ins = new IndexedNumsStream(streamlength); ins.Read(buf, 4, 15); ins.Read(buf, 2, 16); System.Console.WriteLine("hello"); foreach (var b in buf) { Console.WriteLine(b); } }
public void TestNumberedTextWriter() { var sw = new StreamWriter("TestFile1.txt"); var nsw = new NumberedTextWriter(sw); nsw.WriteLine("Hello"); nsw.WriteLine("This"); nsw.WriteLine("is"); nsw.WriteLine("a"); nsw.WriteLine("test"); sw.Close(); nsw.Close(); }
static void Main(string[] args) { NumberedTextWriter NTW = new NumberedTextWriter(Console.Out); NTW.WriteLine("Hello World!"); NTW.WriteLine("Hi"); NTW.WriteLine("Hello World!"); IndexedNumsStream ins = new IndexedNumsStream(20); byte[] buffer = new byte[20]; ins.Read(buffer, 5, 10); foreach (byte i in buffer) { Console.WriteLine(i); } ins.Read(buffer, 0, 20); foreach (byte i in buffer) { Console.WriteLine(i); } ins.Read(buffer, 2, 13); foreach (byte i in buffer) { NTW.WriteLine(i.ToString()); } ins.SetLength(10); ins.Read(buffer, 2, 13); foreach (byte i in buffer) { NTW.WriteLine(i.ToString()); } ins.Position = -5; ins.Read(buffer, 2, 13); foreach (byte i in buffer) { NTW.WriteLine(i.ToString()); } }
public static void Main() { Console.WriteLine("hello, hw1"); CS422.NumberedTextWriter writer = new CS422.NumberedTextWriter(Console.Out); Console.WriteLine("--- NumberedTextWriter Test 1 Constructor ---"); writer.WriteLine("one"); writer.WriteLine("two"); writer.WriteLine("three"); writer.WriteLine("four"); writer.WriteLine("five"); writer.WriteLine("siz"); writer.WriteLine("seven"); writer.WriteLine("eight"); writer = new CS422.NumberedTextWriter(Console.Out, 5); Console.WriteLine("--- NumberedTextWriter Test 2 Constructor ---"); writer.WriteLine("five"); writer.WriteLine("six"); writer.WriteLine("seven"); writer.WriteLine("eight"); writer.WriteLine("nine"); writer.WriteLine("ten"); writer.WriteLine("eleven"); writer.WriteLine("twelve"); CS422.IndexedNumsStream stream = new CS422.IndexedNumsStream(256); byte[] barry = new byte[5]; Console.WriteLine("--- IndexedNumsStream Tests ---"); Console.WriteLine("byte array: "); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- read 5 from beginning of stream ---"); stream.Read(barry, 0, 5); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- read another 5 ---"); stream.Read(barry, 0, 5); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- read another 4 ---"); stream.Read(barry, 0, 4); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- read another 2 into last 2 ---"); stream.Read(barry, barry.Length - 2, 2); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- pos = 253, but read 5 (first 3 should change only)---"); stream.Position = 253; stream.Read(barry, 0, 5); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- try read 5 from end, no change ---"); stream.Read(barry, 0, 5); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } Console.WriteLine("--- change stream Length, read 5 ---"); stream.SetLength(512); stream.Read(barry, 0, 5); for (int i = 0; i < barry.Length; i++) { Console.WriteLine(barry[i]); } }