コード例 #1
0
ファイル: MultiReader.cs プロジェクト: carrie901/mono
		/// <summary> If clone is true then we clone each of the subreaders</summary>
		/// <param name="doClone">
		/// </param>
		/// <returns> New IndexReader, or same one (this) if
		/// reopen/clone is not necessary
		/// </returns>
		/// <throws>  CorruptIndexException </throws>
		/// <throws>  IOException </throws>
		protected internal virtual IndexReader DoReopen(bool doClone)
		{
			EnsureOpen();
			
			bool reopened = false;
			IndexReader[] newSubReaders = new IndexReader[subReaders.Length];
			
			bool success = false;
			try
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					if (doClone)
						newSubReaders[i] = (IndexReader) subReaders[i].Clone();
					else
						newSubReaders[i] = subReaders[i].Reopen();
					// if at least one of the subreaders was updated we remember that
					// and return a new MultiReader
					if (newSubReaders[i] != subReaders[i])
					{
						reopened = true;
					}
				}
				success = true;
			}
			finally
			{
				if (!success && reopened)
				{
					for (int i = 0; i < newSubReaders.Length; i++)
					{
						if (newSubReaders[i] != subReaders[i])
						{
							try
							{
								newSubReaders[i].Close();
							}
							catch (System.IO.IOException ignore)
							{
								// keep going - we want to clean up as much as possible
							}
						}
					}
				}
			}
			
			if (reopened)
			{
				bool[] newDecrefOnClose = new bool[subReaders.Length];
				for (int i = 0; i < subReaders.Length; i++)
				{
					if (newSubReaders[i] == subReaders[i])
					{
						newSubReaders[i].IncRef();
						newDecrefOnClose[i] = true;
					}
				}
				MultiReader mr = new MultiReader(newSubReaders);
				mr.decrefOnClose = newDecrefOnClose;
				mr.SetDisableFakeNorms(GetDisableFakeNorms());
				return mr;
			}
			else
			{
				return this;
			}
		}
コード例 #2
0
        /// <summary> If clone is true then we clone each of the subreaders</summary>
        /// <param name="doClone">
        /// </param>
        /// <returns> New IndexReader, or same one (this) if
        /// reopen/clone is not necessary
        /// </returns>
        /// <throws>  CorruptIndexException </throws>
        /// <throws>  IOException </throws>
        protected internal virtual IndexReader DoReopen(bool doClone)
        {
            EnsureOpen();

            bool reopened = false;

            IndexReader[] newSubReaders = new IndexReader[subReaders.Length];

            bool success = false;

            try
            {
                for (int i = 0; i < subReaders.Length; i++)
                {
                    if (doClone)
                    {
                        newSubReaders[i] = (IndexReader)subReaders[i].Clone();
                    }
                    else
                    {
                        newSubReaders[i] = subReaders[i].Reopen();
                    }
                    // if at least one of the subreaders was updated we remember that
                    // and return a new MultiReader
                    if (newSubReaders[i] != subReaders[i])
                    {
                        reopened = true;
                    }
                }
                success = true;
            }
            finally
            {
                if (!success && reopened)
                {
                    for (int i = 0; i < newSubReaders.Length; i++)
                    {
                        if (newSubReaders[i] != subReaders[i])
                        {
                            try
                            {
                                newSubReaders[i].Close();
                            }
                            catch (System.IO.IOException ignore)
                            {
                                // keep going - we want to clean up as much as possible
                            }
                        }
                    }
                }
            }

            if (reopened)
            {
                bool[] newDecrefOnClose = new bool[subReaders.Length];
                for (int i = 0; i < subReaders.Length; i++)
                {
                    if (newSubReaders[i] == subReaders[i])
                    {
                        newSubReaders[i].IncRef();
                        newDecrefOnClose[i] = true;
                    }
                }
                MultiReader mr = new MultiReader(newSubReaders);
                mr.decrefOnClose = newDecrefOnClose;
                mr.SetDisableFakeNorms(GetDisableFakeNorms());
                return(mr);
            }
            else
            {
                return(this);
            }
        }