コード例 #1
0
ファイル: TestCompoundFile.cs プロジェクト: yonder/mono
        /// <summary>Creates a file of the specified size with random data. </summary>
        private void  CreateRandomFile(Directory dir, System.String name, int size)
        {
            OutputStream os = dir.CreateFile(name);

            for (int i = 0; i < size; i++)
            {
                byte b = (byte)(((new System.Random()).NextDouble()) * 256);
                os.WriteByte(b);
            }
            os.Close();
        }
コード例 #2
0
ファイル: TestCompoundFile.cs プロジェクト: yonder/mono
        /// <summary>Creates a file of the specified size with sequential data. The first
        /// byte is written as the start byte provided. All subsequent bytes are
        /// computed as start + offset where offset is the number of the byte.
        /// </summary>
        private void  CreateSequenceFile(Directory dir, System.String name, byte start, int size)
        {
            OutputStream os = dir.CreateFile(name);

            for (int i = 0; i < size; i++)
            {
                os.WriteByte(start);
                start++;
            }
            os.Close();
        }
コード例 #3
0
ファイル: TestCompoundFile.cs プロジェクト: yonder/mono
        private void  Demo_FSInputStreamBug(FSDirectory fsdir, System.String file)
        {
            // Setup the test file - we need more than 1024 bytes
            OutputStream os = fsdir.CreateFile(file);

            for (int i = 0; i < 2000; i++)
            {
                os.WriteByte((byte)i);
            }
            os.Close();

            InputStream in_Renamed = fsdir.OpenFile(file);

            // This read primes the buffer in InputStream
            byte b = in_Renamed.ReadByte();

            // Close the file
            in_Renamed.Close();

            // ERROR: this call should fail, but succeeds because the buffer
            // is still filled
            b = in_Renamed.ReadByte();

            // ERROR: this call should fail, but succeeds for some reason as well
            in_Renamed.Seek(1099);

            try
            {
                // OK: this call correctly fails. We are now past the 1024 internal
                // buffer, so an actual IO is attempted, which fails
                b = in_Renamed.ReadByte();
            }
            catch (System.IO.IOException e)
            {
            }
            catch (System.Exception)
            {
            }
        }
コード例 #4
0
ファイル: StoreTest.cs プロジェクト: raj581/Marvin
        public static void  Test(int count, bool ram)
        {
            System.Random gen = new System.Random((System.Int32) 1251971);
            int           i;

            System.DateTime veryStart = System.DateTime.Now;
            System.DateTime start     = System.DateTime.Now;

            Directory store;

            if (ram)
            {
                store = new RAMDirectory();
            }
            else
            {
                store = FSDirectory.GetDirectory("test.store", true);
            }

            int LENGTH_MASK = 0xFFF;

            for (i = 0; i < count; i++)
            {
                System.String name   = i + ".dat";
                int           length = gen.Next() & LENGTH_MASK;
                byte          b      = (byte)(gen.Next() & 0x7F);
                //System.out.println("filling " + name + " with " + length + " of " + b);

                OutputStream file = store.CreateFile(name);

                for (int j = 0; j < length; j++)
                {
                    file.WriteByte(b);
                }

                file.Close();
            }

            store.Close();

            System.DateTime end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" total milliseconds to create");

            gen   = new System.Random((System.Int32) 1251971);
            start = System.DateTime.Now;

            if (!ram)
            {
                store = FSDirectory.GetDirectory("test.store", false);
            }

            for (i = 0; i < count; i++)
            {
                System.String name   = i + ".dat";
                int           length = gen.Next() & LENGTH_MASK;
                sbyte         b      = (sbyte)(gen.Next() & 0x7F);
                //System.out.println("reading " + name + " with " + length + " of " + b);

                InputStream file = store.OpenFile(name);

                if (file.Length() != length)
                {
                    throw new System.Exception("length incorrect");
                }

                for (int j = 0; j < length; j++)
                {
                    if (file.ReadByte() != b)
                    {
                        throw new System.Exception("contents incorrect");
                    }
                }

                file.Close();
            }

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" total milliseconds to read");

            gen   = new System.Random((System.Int32) 1251971);
            start = System.DateTime.Now;

            for (i = 0; i < count; i++)
            {
                System.String name = i + ".dat";
                //System.out.println("deleting " + name);
                store.DeleteFile(name);
            }

            end = System.DateTime.Now;

            System.Console.Out.Write(end.Ticks - start.Ticks);
            System.Console.Out.WriteLine(" total milliseconds to delete");

            System.Console.Out.Write(end.Ticks - veryStart.Ticks);
            System.Console.Out.WriteLine(" total milliseconds");

            store.Close();
        }