Exemplo n.º 1
0
        private ByteBufferIndexInput BuildSlice(long offset, long length)
        {
            if (buffers == null)
            {
                throw new ObjectDisposedException(this.GetType().GetTypeInfo().FullName, "Already closed: " + this);
            }
            if (offset < 0 || length < 0 || offset + length > this.length)
            {
                throw new ArgumentException("slice() " + sliceDescription + " out of bounds: offset=" + offset + ",length=" + length + ",fileLength=" + this.length + ": " + this);
            }

            // include our own offset into the final offset:
            offset += this.offset;

            ByteBufferIndexInput clone = (ByteBufferIndexInput)base.Clone();

            clone.isClone = true;
            // we keep clone.clones, so it shares the same map with original and we have no additional cost on clones
            Debug.Assert(clone.clones == this.clones);
            clone.buffers = BuildSlice(buffers, offset, length);
            clone.offset  = (int)(offset & chunkSizeMask);
            clone.length  = length;

            // register the new clone in our clone list to clean it up on closing:
            if (clones != null)
            {
                this.clones.Put(clone, new BoolRefWrapper(true));
            }

            return(clone);
        }
Exemplo n.º 2
0
        public override sealed object Clone()
        {
            ByteBufferIndexInput clone = BuildSlice(0L, this.length);

            try
            {
                clone.Seek(GetFilePointer());
            }
            catch (IOException ioe)
            {
                throw new Exception("Should never happen: " + this, ioe);
            }

            return(clone);
        }
Exemplo n.º 3
0
        public override sealed object Clone()
        {
            ByteBufferIndexInput clone = BuildSlice(0L, this.length);

            try
            {
                clone.Seek(Position); // LUCENENET specific: Renamed from getFilePointer() to match FileStream
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                throw RuntimeException.Create("Should never happen: " + this, ioe);
            }

            return(clone);
        }
Exemplo n.º 4
0
        private ByteBufferIndexInput BuildSlice(long offset, long length)
        {
            // LUCENENET: Refactored to avoid calls on invalid conditions instead of
            // catching and re-throwing exceptions in the normal workflow.
            EnsureOpen();
            // LUCENENET: Added .NET-sytle guard clauses that throw ArgumementOutOfRangeException
            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(offset), "offset may not be negative.");
            }
            if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length), "length may not be negative.");
            }
            if (offset + length > this.length)
            {
                throw new ArgumentException("slice() " + sliceDescription + " out of bounds: offset=" + offset + ",length=" + length + ",fileLength=" + this.length + ": " + this);
            }

            // include our own offset into the final offset:
            offset += this.offset;

            ByteBufferIndexInput clone = (ByteBufferIndexInput)base.Clone();

            clone.isClone = true;
            // we keep clone.clones, so it shares the same map with original and we have no additional cost on clones
            if (Debugging.AssertsEnabled)
            {
                Debugging.Assert(clone.clones == this.clones);
            }
            clone.buffers = BuildSlice(buffers, offset, length);
            clone.offset  = (int)(offset & chunkSizeMask);
            clone.length  = length;

            // register the new clone in our clone list to clean it up on closing:
            if (clones != null)
            {
                this.clones.Add(clone, true);
            }

            return(clone);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a slice of this index input, with the given description, offset, and length. The slice is seeked to the beginning.
        /// </summary>
        public ByteBufferIndexInput Slice(string sliceDescription, long offset, long length)
        {
            if (isClone) // well we could, but this is stupid
            {
                throw new InvalidOperationException("cannot slice() " + sliceDescription + " from a cloned IndexInput: " + this);
            }
            ByteBufferIndexInput clone = BuildSlice(offset, length);

            clone.sliceDescription = sliceDescription;
            try
            {
                clone.Seek(0L);
            }
            catch (IOException ioe)
            {
                throw new Exception("Should never happen: " + this, ioe);
            }

            return(clone);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a slice of this index input, with the given description, offset, and length. The slice is seeked to the beginning.
        /// </summary>
        public ByteBufferIndexInput Slice(string sliceDescription, long offset, long length)
        {
            // LUCENENET: Refactored to avoid calls on invalid conditions instead of
            // catching and re-throwing exceptions in the normal workflow.
            EnsureOpen();
            if (isClone) // well we could, but this is stupid
            {
                throw IllegalStateException.Create("cannot Slice() " + sliceDescription + " from a cloned IndexInput: " + this);
            }
            ByteBufferIndexInput clone = BuildSlice(offset, length);

            clone.sliceDescription = sliceDescription;
            try
            {
                clone.Seek(0L);
            }
            catch (Exception ioe) when(ioe.IsIOException())
            {
                throw RuntimeException.Create("Should never happen: " + this, ioe);
            }

            return(clone);
        }