Dispose() public abstract method

Closes the stream to further operations.
public abstract Dispose ( ) : void
return void
コード例 #1
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (proxStream != null)
     {
         proxStream.Dispose();
     }
 }
コード例 #2
0
        protected virtual void Dispose(bool disposing)
        {
            if (isDisposed)
            {
                return;
            }

            freqStream.Dispose();
            if (skipListReader != null)
            {
                skipListReader.Dispose();
            }

            isDisposed = true;
        }
コード例 #3
0
ファイル: TestMultiMMap.cs プロジェクト: yohikofox/lucenenet
 public virtual void TestSeekEnd()
 {
     for (int i = 0; i < 17; i++)
     {
         MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testSeekEnd"), null, 1 << i);
         IndexOutput   io      = mmapDir.CreateOutput("bytes", NewIOContext(Random()));
         var           bytes   = new byte[1 << i];
         Random().NextBytes(bytes);
         io.WriteBytes(bytes, bytes.Length);
         io.Dispose();
         IndexInput ii     = mmapDir.OpenInput("bytes", NewIOContext(Random()));
         var        actual = new byte[1 << i];
         ii.ReadBytes(actual, 0, actual.Length);
         Assert.AreEqual(new BytesRef(bytes), new BytesRef(actual));
         ii.Seek(1 << i);
         ii.Dispose();
         mmapDir.Dispose();
     }
 }
コード例 #4
0
        public virtual void TestSeekToEOFThenBack()
        {
            RAMDirectory dir = new RAMDirectory();

            IndexOutput o     = dir.CreateOutput("out", NewIOContext(Random));
            var         bytes = new byte[3 * RAMInputStream.BUFFER_SIZE];

            o.WriteBytes(bytes, 0, bytes.Length);
            o.Dispose();

            IndexInput i = dir.OpenInput("out", NewIOContext(Random));

            i.Seek(2 * RAMInputStream.BUFFER_SIZE - 1);
            i.Seek(3 * RAMInputStream.BUFFER_SIZE);
            i.Seek(RAMInputStream.BUFFER_SIZE);
            i.ReadBytes(bytes, 0, 2 * RAMInputStream.BUFFER_SIZE);
            i.Dispose();
            dir.Dispose();
        }
コード例 #5
0
 public override void Dispose()
 {
     try
     {
         // turn on the following to look for leaks closing inputs,
         // after fixing TestTransactions
         // Dir.MaybeThrowDeterministicException();
     }
     finally
     {
         Closed = true;
         @delegate.Dispose();
         // Pending resolution on LUCENE-686 we may want to
         // remove the conditional check so we also track that
         // all clones get closed:
         if (!IsClone)
         {
             Dir.RemoveIndexInput(this, Name);
         }
     }
 }
コード例 #6
0
        public virtual void TestDirectInstantiation()
        {
            DirectoryInfo path = CreateTempDir("testDirectInstantiation");

            byte[] largeBuffer = new byte[Random().Next(256 * 1024)], largeReadBuffer = new byte[largeBuffer.Length];
            for (int i = 0; i < largeBuffer.Length; i++)
            {
                largeBuffer[i] = (byte)i; // automatically loops with modulo
            }

            var dirs = new FSDirectory[] { new SimpleFSDirectory(path, null), new NIOFSDirectory(path, null), new MMapDirectory(path, null) };

            for (int i = 0; i < dirs.Length; i++)
            {
                FSDirectory dir = dirs[i];
                dir.EnsureOpen();
                string      fname    = "foo." + i;
                string      lockname = "foo" + i + ".lck";
                IndexOutput @out     = dir.CreateOutput(fname, NewIOContext(Random()));
                @out.WriteByte((byte)(sbyte)i);
                @out.WriteBytes(largeBuffer, largeBuffer.Length);
                @out.Dispose();

                for (int j = 0; j < dirs.Length; j++)
                {
                    FSDirectory d2 = dirs[j];
                    d2.EnsureOpen();
                    Assert.IsTrue(SlowFileExists(d2, fname));
                    Assert.AreEqual(1 + largeBuffer.Length, d2.FileLength(fname));

                    // don't do read tests if unmapping is not supported!
                    if (d2 is MMapDirectory && !((MMapDirectory)d2).UseUnmap)
                    {
                        continue;
                    }

                    IndexInput input = d2.OpenInput(fname, NewIOContext(Random()));
                    Assert.AreEqual((byte)i, input.ReadByte());
                    // read array with buffering enabled
                    Arrays.Fill(largeReadBuffer, (byte)0);
                    input.ReadBytes(largeReadBuffer, 0, largeReadBuffer.Length, true);
                    Assert.AreEqual(largeBuffer, largeReadBuffer);
                    // read again without using buffer
                    input.Seek(1L);
                    Arrays.Fill(largeReadBuffer, (byte)0);
                    input.ReadBytes(largeReadBuffer, 0, largeReadBuffer.Length, false);
                    Assert.AreEqual(largeBuffer, largeReadBuffer);
                    input.Dispose();
                }

                // delete with a different dir
                dirs[(i + 1) % dirs.Length].DeleteFile(fname);

                for (int j = 0; j < dirs.Length; j++)
                {
                    FSDirectory d2 = dirs[j];
                    Assert.IsFalse(SlowFileExists(d2, fname));
                }

                Lock @lock = dir.MakeLock(lockname);
                Assert.IsTrue(@lock.Obtain());

                for (int j = 0; j < dirs.Length; j++)
                {
                    FSDirectory d2    = dirs[j];
                    Lock        lock2 = d2.MakeLock(lockname);
                    try
                    {
                        Assert.IsFalse(lock2.Obtain(1));
                    }
                    catch (LockObtainFailedException e)
                    {
                        // OK
                    }
                }

                @lock.Dispose();

                // now lock with different dir
                @lock = dirs[(i + 1) % dirs.Length].MakeLock(lockname);
                Assert.IsTrue(@lock.Obtain());
                @lock.Dispose();
            }

            for (int i = 0; i < dirs.Length; i++)
            {
                FSDirectory dir = dirs[i];
                dir.EnsureOpen();
                dir.Dispose();
                Assert.IsFalse(dir.IsOpen);
            }
        }
コード例 #7
0
ファイル: TestCopyBytes.cs プロジェクト: zhangbo27/lucenenet
        public virtual void TestCopyBytesMem()
        {
            int num = AtLeast(10);

            for (int iter = 0; iter < num; iter++)
            {
                Directory dir = NewDirectory();
                if (VERBOSE)
                {
                    Console.WriteLine("TEST: iter=" + iter + " dir=" + dir);
                }

                // make random file
                IndexOutput @out     = dir.CreateOutput("test", NewIOContext(Random()));
                var         bytes    = new byte[TestUtil.NextInt(Random(), 1, 77777)];
                int         size     = TestUtil.NextInt(Random(), 1, 1777777);
                int         upto     = 0;
                int         byteUpto = 0;
                while (upto < size)
                {
                    bytes[byteUpto++] = Value(upto);
                    upto++;
                    if (byteUpto == bytes.Length)
                    {
                        @out.WriteBytes(bytes, 0, bytes.Length);
                        byteUpto = 0;
                    }
                }

                @out.WriteBytes(bytes, 0, byteUpto);
                Assert.AreEqual(size, @out.GetFilePointer());
                @out.Dispose();
                Assert.AreEqual(size, dir.FileLength("test"));

                // copy from test -> test2
                IndexInput @in = dir.OpenInput("test", NewIOContext(Random()));

                @out = dir.CreateOutput("test2", NewIOContext(Random()));

                upto = 0;
                while (upto < size)
                {
                    if (Random().NextBoolean())
                    {
                        @out.WriteByte(@in.ReadByte());
                        upto++;
                    }
                    else
                    {
                        int chunk = Math.Min(TestUtil.NextInt(Random(), 1, bytes.Length), size - upto);
                        @out.CopyBytes(@in, chunk);
                        upto += chunk;
                    }
                }
                Assert.AreEqual(size, upto);
                @out.Dispose();
                @in.Dispose();

                // verify
                IndexInput in2 = dir.OpenInput("test2", NewIOContext(Random()));
                upto = 0;
                while (upto < size)
                {
                    if (Random().NextBoolean())
                    {
                        var v = in2.ReadByte();
                        Assert.AreEqual(Value(upto), v);
                        upto++;
                    }
                    else
                    {
                        int limit = Math.Min(TestUtil.NextInt(Random(), 1, bytes.Length), size - upto);
                        in2.ReadBytes(bytes, 0, limit);
                        for (int byteIdx = 0; byteIdx < limit; byteIdx++)
                        {
                            Assert.AreEqual(Value(upto), bytes[byteIdx]);
                            upto++;
                        }
                    }
                }
                in2.Dispose();

                dir.DeleteFile("test");
                dir.DeleteFile("test2");

                dir.Dispose();
            }
        }
コード例 #8
0
ファイル: Directory.cs プロジェクト: leotohill/lucene.net
 public override void Dispose()
 {
     @base.Dispose();
 }
コード例 #9
0
ファイル: Directory.cs プロジェクト: leotohill/lucene.net
 public override void Dispose(bool disposing)
 {
     @base.Dispose();
 }
コード例 #10
0
 /// <summary>Closes the enumeration to further activity, freeing resources. </summary>
 protected override void Dispose(bool disposing)
 {
     input.Dispose();
 }
コード例 #11
0
ファイル: TestMultiMMap.cs プロジェクト: yohikofox/lucenenet
        public virtual void TestCloneSliceSafety()
        {
            MMapDirectory mmapDir = new MMapDirectory(CreateTempDir("testCloneSliceSafety"));
            IndexOutput   io      = mmapDir.CreateOutput("bytes", NewIOContext(Random()));

            io.WriteInt32(1);
            io.WriteInt32(2);
            io.Dispose();
            IndexInputSlicer slicer = mmapDir.CreateSlicer("bytes", NewIOContext(Random()));
            IndexInput       one    = slicer.OpenSlice("first int", 0, 4);
            IndexInput       two    = slicer.OpenSlice("second int", 4, 4);
            IndexInput       three  = (IndexInput)one.Clone(); // clone of clone
            IndexInput       four   = (IndexInput)two.Clone(); // clone of clone

            slicer.Dispose();
            try
            {
                one.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                two.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                three.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            try
            {
                four.ReadInt32();
                Assert.Fail("Must throw ObjectDisposedException");
            }
#pragma warning disable 168
            catch (ObjectDisposedException ignore)
#pragma warning restore 168
            {
                // pass
            }
            one.Dispose();
            two.Dispose();
            three.Dispose();
            four.Dispose();
            // test double-close of slicer:
            slicer.Dispose();
            mmapDir.Dispose();
        }
コード例 #12
0
 private void RunReadBytesAndClose(IndexInput input, int bufferSize, Random r)
 {
     try
     {
         RunReadBytes(input, bufferSize, r);
     }
     finally
     {
         input.Dispose();
     }
 }
コード例 #13
0
 public override void Dispose()
 {
     Main.Dispose();
 }