Exemple #1
0
        public virtual void  TestTwoFiles()
        {
            CreateSequenceFile(dir, "d1", (byte)0, 15);
            CreateSequenceFile(dir, "d2", (byte)0, 114);

            CompoundFileWriter csw = new CompoundFileWriter(dir, "d.csf");

            csw.AddFile("d1");
            csw.AddFile("d2");
            csw.Close();

            CompoundFileReader csr      = new CompoundFileReader(dir, "d.csf");
            InputStream        expected = dir.OpenFile("d1");
            InputStream        actual   = csr.OpenFile("d1");

            AssertSameStreams("d1", expected, actual);
            AssertSameSeekBehavior("d1", expected, actual);
            expected.Close();
            actual.Close();

            expected = dir.OpenFile("d2");
            actual   = csr.OpenFile("d2");
            AssertSameStreams("d2", expected, actual);
            AssertSameSeekBehavior("d2", expected, actual);
            expected.Close();
            actual.Close();
            csr.Close();
        }
Exemple #2
0
        public virtual void  TestClonedStreamsClosing()
        {
            SetUp_2();
            CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");

            // basic clone
            InputStream expected = dir.OpenFile("f11");

            Assert.IsTrue(_TestHelper.IsFSInputStreamOpen(expected));

            InputStream one = cr.OpenFile("f11");

            Assert.IsTrue(IsCSInputStreamOpen(one));

            InputStream two = (InputStream)one.Clone();

            Assert.IsTrue(IsCSInputStreamOpen(two));

            AssertSameStreams("basic clone one", expected, one);
            expected.Seek(0);
            AssertSameStreams("basic clone two", expected, two);

            // Now close the first stream
            one.Close();
            Assert.IsTrue(IsCSInputStreamOpen(one), "Only close when cr is closed");

            // The following should really fail since we couldn't expect to
            // access a file once close has been called on it (regardless of
            // buffering and/or clone magic)
            expected.Seek(0);
            two.Seek(0);
            AssertSameStreams("basic clone two/2", expected, two);


            // Now close the compound reader
            cr.Close();
            Assert.IsFalse(IsCSInputStreamOpen(one), "Now closed one");
            Assert.IsFalse(IsCSInputStreamOpen(two), "Now closed two");

            // The following may also fail since the compound stream is closed
            expected.Seek(0);
            two.Seek(0);
            //AssertSameStreams("basic clone two/3", expected, two);


            // Now close the second clone
            two.Close();
            expected.Seek(0);
            two.Seek(0);
            //AssertSameStreams("basic clone two/4", expected, two);

            expected.Close();
        }
Exemple #3
0
        public virtual void  TestRandomFiles()
        {
            // Setup the test segment
            System.String segment = "test";
            int           chunk   = 1024; // internal buffer size used by the stream

            CreateRandomFile(dir, segment + ".zero", 0);
            CreateRandomFile(dir, segment + ".one", 1);
            CreateRandomFile(dir, segment + ".ten", 10);
            CreateRandomFile(dir, segment + ".hundred", 100);
            CreateRandomFile(dir, segment + ".big1", chunk);
            CreateRandomFile(dir, segment + ".big2", chunk - 1);
            CreateRandomFile(dir, segment + ".big3", chunk + 1);
            CreateRandomFile(dir, segment + ".big4", 3 * chunk);
            CreateRandomFile(dir, segment + ".big5", 3 * chunk - 1);
            CreateRandomFile(dir, segment + ".big6", 3 * chunk + 1);
            CreateRandomFile(dir, segment + ".big7", 1000 * chunk);

            // Setup extraneous files
            CreateRandomFile(dir, "onetwothree", 100);
            CreateRandomFile(dir, segment + ".notIn", 50);
            CreateRandomFile(dir, segment + ".notIn2", 51);

            // Now test
            CompoundFileWriter csw = new CompoundFileWriter(dir, "test.cfs");

            System.String[] data = new System.String[] { ".zero", ".one", ".ten", ".hundred", ".big1", ".big2", ".big3", ".big4", ".big5", ".big6", ".big7" };
            for (int i = 0; i < data.Length; i++)
            {
                csw.AddFile(segment + data[i]);
            }
            csw.Close();

            CompoundFileReader csr = new CompoundFileReader(dir, "test.cfs");

            for (int i = 0; i < data.Length; i++)
            {
                InputStream check = dir.OpenFile(segment + data[i]);
                InputStream test  = csr.OpenFile(segment + data[i]);
                AssertSameStreams(data[i], check, test);
                AssertSameSeekBehavior(data[i], check, test);
                test.Close();
                check.Close();
            }
            csr.Close();
        }
Exemple #4
0
        public virtual void  TestFileNotFound()
        {
            SetUp_2();
            CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");

            // Open two files
            try
            {
                InputStream e1 = cr.OpenFile("bogus");
                Assert.Fail("File not found");
            }
            catch (System.IO.IOException e)
            {
                /* success */
                //System.out.println("SUCCESS: File Not Found: " + e);
            }

            cr.Close();
        }
Exemple #5
0
        public virtual void  TestSingleFile()
        {
            int[] data = new int[] { 0, 1, 10, 100 };
            for (int i = 0; i < data.Length; i++)
            {
                System.String name = "t" + data[i];
                CreateSequenceFile(dir, name, (byte)0, data[i]);
                CompoundFileWriter csw = new CompoundFileWriter(dir, name + ".cfs");
                csw.AddFile(name);
                csw.Close();

                CompoundFileReader csr      = new CompoundFileReader(dir, name + ".cfs");
                InputStream        expected = dir.OpenFile(name);
                InputStream        actual   = csr.OpenFile(name);
                AssertSameStreams(name, expected, actual);
                AssertSameSeekBehavior(name, expected, actual);
                expected.Close();
                actual.Close();
                csr.Close();
            }
        }
Exemple #6
0
        public virtual void  TestReadPastEOF()
        {
            SetUp_2();
            CompoundFileReader cr         = new CompoundFileReader(dir, "f.comp");
            InputStream        is_Renamed = cr.OpenFile("f2");

            is_Renamed.Seek(is_Renamed.Length() - 10);
            byte[] b = new byte[100];
            is_Renamed.ReadBytes(b, 0, 10);

            try
            {
                byte test = is_Renamed.ReadByte();
                Assert.Fail("Single byte read past end of file");
            }
            catch (System.IO.IOException e)
            {
                /* success */
                //System.out.println("SUCCESS: single byte read past end of file: " + e);
            }

            is_Renamed.Seek(is_Renamed.Length() - 10);
            try
            {
                is_Renamed.ReadBytes(b, 0, 50);
                Assert.Fail("Block read past end of file");
            }
            catch (System.IO.IOException e)
            {
                /* success */
                //System.out.println("SUCCESS: block read past end of file: " + e);
            }

            is_Renamed.Close();
            cr.Close();
        }
Exemple #7
0
        public virtual void  TestRandomAccessClones()
        {
            SetUp_2();
            CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");

            // Open two files
            InputStream e1 = cr.OpenFile("f11");
            InputStream e2 = cr.OpenFile("f3");

            InputStream a1 = (InputStream)e1.Clone();
            InputStream a2 = (InputStream)e2.Clone();

            // Seek the first pair
            e1.Seek(100);
            a1.Seek(100);
            Assert.AreEqual(100, e1.GetFilePointer());
            Assert.AreEqual(100, a1.GetFilePointer());
            byte be1 = e1.ReadByte();
            byte ba1 = a1.ReadByte();

            Assert.AreEqual(be1, ba1);

            // Now seek the second pair
            e2.Seek(1027);
            a2.Seek(1027);
            Assert.AreEqual(1027, e2.GetFilePointer());
            Assert.AreEqual(1027, a2.GetFilePointer());
            byte be2 = e2.ReadByte();
            byte ba2 = a2.ReadByte();

            Assert.AreEqual(be2, ba2);

            // Now make sure the first one didn't move
            Assert.AreEqual(101, e1.GetFilePointer());
            Assert.AreEqual(101, a1.GetFilePointer());
            be1 = e1.ReadByte();
            ba1 = a1.ReadByte();
            Assert.AreEqual(be1, ba1);

            // Now more the first one again, past the buffer length
            e1.Seek(1910);
            a1.Seek(1910);
            Assert.AreEqual(1910, e1.GetFilePointer());
            Assert.AreEqual(1910, a1.GetFilePointer());
            be1 = e1.ReadByte();
            ba1 = a1.ReadByte();
            Assert.AreEqual(be1, ba1);

            // Now make sure the second set didn't move
            Assert.AreEqual(1028, e2.GetFilePointer());
            Assert.AreEqual(1028, a2.GetFilePointer());
            be2 = e2.ReadByte();
            ba2 = a2.ReadByte();
            Assert.AreEqual(be2, ba2);

            // Move the second set back, again cross the buffer size
            e2.Seek(17);
            a2.Seek(17);
            Assert.AreEqual(17, e2.GetFilePointer());
            Assert.AreEqual(17, a2.GetFilePointer());
            be2 = e2.ReadByte();
            ba2 = a2.ReadByte();
            Assert.AreEqual(be2, ba2);

            // Finally, make sure the first set didn't move
            // Now make sure the first one didn't move
            Assert.AreEqual(1911, e1.GetFilePointer());
            Assert.AreEqual(1911, a1.GetFilePointer());
            be1 = e1.ReadByte();
            ba1 = a1.ReadByte();
            Assert.AreEqual(be1, ba1);

            e1.Close();
            e2.Close();
            a1.Close();
            a2.Close();
            cr.Close();
        }
Exemple #8
0
		public virtual void  TestFileNotFound()
		{
			SetUp_2();
			CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
			
			// Open two files
			try
			{
				InputStream e1 = cr.OpenFile("bogus");
				Assert.Fail("File not found");
			}
			catch (System.IO.IOException e)
			{
				/* success */
				//System.out.println("SUCCESS: File Not Found: " + e);
			}
			
			cr.Close();
		}
Exemple #9
0
		public virtual void  TestReadPastEOF()
		{
			SetUp_2();
			CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
			InputStream is_Renamed = cr.OpenFile("f2");
			is_Renamed.Seek(is_Renamed.Length() - 10);
			byte[] b = new byte[100];
			is_Renamed.ReadBytes(b, 0, 10);
			
			try
			{
				byte test = is_Renamed.ReadByte();
				Assert.Fail("Single byte read past end of file");
			}
			catch (System.IO.IOException e)
			{
				/* success */
				//System.out.println("SUCCESS: single byte read past end of file: " + e);
			}
			
			is_Renamed.Seek(is_Renamed.Length() - 10);
			try
			{
				is_Renamed.ReadBytes(b, 0, 50);
				Assert.Fail("Block read past end of file");
			}
			catch (System.IO.IOException e)
			{
				/* success */
				//System.out.println("SUCCESS: block read past end of file: " + e);
			}
			
			is_Renamed.Close();
			cr.Close();
		}
Exemple #10
0
        public virtual void  TestRandomAccessClones()
		{
			SetUp_2();
			CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
			
			// Open two files
			InputStream e1 = cr.OpenFile("f11");
			InputStream e2 = cr.OpenFile("f3");
			
			InputStream a1 = (InputStream) e1.Clone();
			InputStream a2 = (InputStream) e2.Clone();
			
			// Seek the first pair
			e1.Seek(100);
			a1.Seek(100);
			Assert.AreEqual(100, e1.GetFilePointer());
			Assert.AreEqual(100, a1.GetFilePointer());
			byte be1 = e1.ReadByte();
			byte ba1 = a1.ReadByte();
			Assert.AreEqual(be1, ba1);
			
			// Now seek the second pair
			e2.Seek(1027);
			a2.Seek(1027);
			Assert.AreEqual(1027, e2.GetFilePointer());
			Assert.AreEqual(1027, a2.GetFilePointer());
			byte be2 = e2.ReadByte();
			byte ba2 = a2.ReadByte();
			Assert.AreEqual(be2, ba2);
			
			// Now make sure the first one didn't move
			Assert.AreEqual(101, e1.GetFilePointer());
			Assert.AreEqual(101, a1.GetFilePointer());
			be1 = e1.ReadByte();
			ba1 = a1.ReadByte();
			Assert.AreEqual(be1, ba1);
			
			// Now more the first one again, past the buffer length
			e1.Seek(1910);
			a1.Seek(1910);
			Assert.AreEqual(1910, e1.GetFilePointer());
			Assert.AreEqual(1910, a1.GetFilePointer());
			be1 = e1.ReadByte();
			ba1 = a1.ReadByte();
			Assert.AreEqual(be1, ba1);
			
			// Now make sure the second set didn't move
			Assert.AreEqual(1028, e2.GetFilePointer());
			Assert.AreEqual(1028, a2.GetFilePointer());
			be2 = e2.ReadByte();
			ba2 = a2.ReadByte();
			Assert.AreEqual(be2, ba2);
			
			// Move the second set back, again cross the buffer size
			e2.Seek(17);
			a2.Seek(17);
			Assert.AreEqual(17, e2.GetFilePointer());
			Assert.AreEqual(17, a2.GetFilePointer());
			be2 = e2.ReadByte();
			ba2 = a2.ReadByte();
			Assert.AreEqual(be2, ba2);
			
			// Finally, make sure the first set didn't move
			// Now make sure the first one didn't move
			Assert.AreEqual(1911, e1.GetFilePointer());
			Assert.AreEqual(1911, a1.GetFilePointer());
			be1 = e1.ReadByte();
			ba1 = a1.ReadByte();
			Assert.AreEqual(be1, ba1);
			
			e1.Close();
			e2.Close();
			a1.Close();
			a2.Close();
			cr.Close();
		}
Exemple #11
0
		public virtual void  TestClonedStreamsClosing()
		{
			SetUp_2();
			CompoundFileReader cr = new CompoundFileReader(dir, "f.comp");
			
			// basic clone
			InputStream expected = dir.OpenFile("f11");
			Assert.IsTrue(_TestHelper.IsFSInputStreamOpen(expected));
			
			InputStream one = cr.OpenFile("f11");
			Assert.IsTrue(IsCSInputStreamOpen(one));
			
			InputStream two = (InputStream) one.Clone();
			Assert.IsTrue(IsCSInputStreamOpen(two));
			
			AssertSameStreams("basic clone one", expected, one);
			expected.Seek(0);
			AssertSameStreams("basic clone two", expected, two);
			
			// Now close the first stream
			one.Close();
			Assert.IsTrue(IsCSInputStreamOpen(one), "Only close when cr is closed");
			
			// The following should really fail since we couldn't expect to
			// access a file once close has been called on it (regardless of
			// buffering and/or clone magic)
			expected.Seek(0);
			two.Seek(0);
			AssertSameStreams("basic clone two/2", expected, two);
			
			
			// Now close the compound reader
			cr.Close();
			Assert.IsFalse(IsCSInputStreamOpen(one), "Now closed one");
			Assert.IsFalse(IsCSInputStreamOpen(two), "Now closed two");
			
			// The following may also fail since the compound stream is closed
			expected.Seek(0);
			two.Seek(0);
			//AssertSameStreams("basic clone two/3", expected, two);
			
			
			// Now close the second clone
			two.Close();
			expected.Seek(0);
			two.Seek(0);
			//AssertSameStreams("basic clone two/4", expected, two);
			
			expected.Close();
		}
Exemple #12
0
        public virtual void  TestRandomFiles()
		{
			// Setup the test segment
			System.String segment = "test";
			int chunk = 1024; // internal buffer size used by the stream
			CreateRandomFile(dir, segment + ".zero", 0);
			CreateRandomFile(dir, segment + ".one", 1);
			CreateRandomFile(dir, segment + ".ten", 10);
			CreateRandomFile(dir, segment + ".hundred", 100);
			CreateRandomFile(dir, segment + ".big1", chunk);
			CreateRandomFile(dir, segment + ".big2", chunk - 1);
			CreateRandomFile(dir, segment + ".big3", chunk + 1);
			CreateRandomFile(dir, segment + ".big4", 3 * chunk);
			CreateRandomFile(dir, segment + ".big5", 3 * chunk - 1);
			CreateRandomFile(dir, segment + ".big6", 3 * chunk + 1);
			CreateRandomFile(dir, segment + ".big7", 1000 * chunk);
			
			// Setup extraneous files
			CreateRandomFile(dir, "onetwothree", 100);
			CreateRandomFile(dir, segment + ".notIn", 50);
			CreateRandomFile(dir, segment + ".notIn2", 51);
			
			// Now test
			CompoundFileWriter csw = new CompoundFileWriter(dir, "test.cfs");
			System.String[] data = new System.String[]{".zero", ".one", ".ten", ".hundred", ".big1", ".big2", ".big3", ".big4", ".big5", ".big6", ".big7"};
			for (int i = 0; i < data.Length; i++)
			{
				csw.AddFile(segment + data[i]);
			}
			csw.Close();
			
			CompoundFileReader csr = new CompoundFileReader(dir, "test.cfs");
			for (int i = 0; i < data.Length; i++)
			{
				InputStream check = dir.OpenFile(segment + data[i]);
				InputStream test = csr.OpenFile(segment + data[i]);
				AssertSameStreams(data[i], check, test);
				AssertSameSeekBehavior(data[i], check, test);
				test.Close();
				check.Close();
			}
			csr.Close();
		}
Exemple #13
0
        public virtual void  TestTwoFiles()
		{
			CreateSequenceFile(dir, "d1", (byte) 0, 15);
			CreateSequenceFile(dir, "d2", (byte) 0, 114);
			
			CompoundFileWriter csw = new CompoundFileWriter(dir, "d.csf");
			csw.AddFile("d1");
			csw.AddFile("d2");
			csw.Close();
			
			CompoundFileReader csr = new CompoundFileReader(dir, "d.csf");
			InputStream expected = dir.OpenFile("d1");
			InputStream actual = csr.OpenFile("d1");
			AssertSameStreams("d1", expected, actual);
			AssertSameSeekBehavior("d1", expected, actual);
			expected.Close();
			actual.Close();
			
			expected = dir.OpenFile("d2");
			actual = csr.OpenFile("d2");
			AssertSameStreams("d2", expected, actual);
			AssertSameSeekBehavior("d2", expected, actual);
			expected.Close();
			actual.Close();
			csr.Close();
		}
Exemple #14
0
		public virtual void  TestSingleFile()
		{
			int[] data = new int[]{0, 1, 10, 100};
			for (int i = 0; i < data.Length; i++)
			{
				System.String name = "t" + data[i];
				CreateSequenceFile(dir, name, (byte) 0, data[i]);
				CompoundFileWriter csw = new CompoundFileWriter(dir, name + ".cfs");
				csw.AddFile(name);
				csw.Close();
				
				CompoundFileReader csr = new CompoundFileReader(dir, name + ".cfs");
				InputStream expected = dir.OpenFile(name);
				InputStream actual = csr.OpenFile(name);
				AssertSameStreams(name, expected, actual);
				AssertSameSeekBehavior(name, expected, actual);
				expected.Close();
				actual.Close();
				csr.Close();
			}
		}