Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
        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());
            }
        }
Beispiel #4
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]);
        }
    }