private ByteBufferIndexInput BuildSlice(long offset, long length) { if (buffers == null) { throw new ObjectDisposedException(this.GetType().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 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); }
private ByteBufferIndexInput BuildSlice(long offset, long length) { if (buffers == null) { throw new AlreadyClosedException("Already closed: " + this); } if (offset < 0 || length < 0 || offset + length > this.Length_Renamed) { throw new System.ArgumentException("slice() " + SliceDescription + " out of bounds: offset=" + offset + ",length=" + length + ",fileLength=" + this.Length_Renamed + ": " + 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_Renamed = 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); }
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); }
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); }
public override sealed object Clone() { ByteBufferIndexInput clone = BuildSlice(0L, this.Length_Renamed); try { clone.Seek(FilePointer); } catch (System.IO.IOException ioe) { throw new Exception("Should never happen: " + this, ioe); } return(clone); }
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); }
/// <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); }
/// <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); }