Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            int bytesRead;

            buffer           = new byte[1000];
            myIndexNumStream = new IndexedNumsStream(255);
            try {
                bytesRead = myIndexNumStream.Read(buffer, 0, 300);

                for (int i = 0; i < bytesRead; i++)
                {
                    Console.WriteLine("{0} : [{1}]", i, buffer[i]);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            try {
                bytesRead = myIndexNumStream.Read(buffer, -10, 300);

                for (int i = 0; i < bytesRead; i++)
                {
                    Console.WriteLine("{0} : [{1}]", i, buffer[i]);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        public void TestIndexedNumsStream_Position_negative()
        {
            var ins = new IndexedNumsStream(5);

            ins.Position = -1;
            Assert.AreEqual(0, ins.Position);

            ins.Position = -100;
            Assert.AreEqual(0, ins.Position);
        }
Exemplo n.º 4
0
        public void TestIndexedNumsStream_Position()
        {
            var streamlength = 50;
            var ins          = new IndexedNumsStream(streamlength);

            ins.Position = 3;
            Assert.AreEqual(3, ins.Position);

            ins.Position = 49;
            Assert.AreEqual(49, ins.Position);
        }
Exemplo n.º 5
0
        public void TestIndexedNumsStream_Position_greater()
        {
            var streamlength = 5;
            var ins          = new IndexedNumsStream(streamlength);

            ins.Position = 6;
            Assert.AreEqual(streamlength, ins.Position);

            ins.Position = 600;
            Assert.AreEqual(streamlength, ins.Position);
        }
Exemplo n.º 6
0
        public void TestIndexedNumsStream_negative2()
        {
            var streamlength = 50;
            var ins          = new IndexedNumsStream(streamlength);

            // test for negative -> should be set to 0
            ins.SetLength(-1);
            Assert.AreEqual(0, ins.Length);

            // other case is set to that length
            ins.SetLength(100);
            Assert.AreEqual(100, ins.Length);
        }
        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());
            }
        }
Exemplo n.º 8
0
    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]);
        }
    }