Lucene.Net.Store.NIOFSDirectory.NIOFSIndexInput.ReadInternal C# (CSharp) Method

ReadInternal() protected method

protected ReadInternal ( byte b, int offset, int len ) : void
b byte
offset int
len int
return void
            protected internal override void ReadInternal(byte[] b, int offset, int len)
            {
                ByteBuffer bb;

                // Determine the ByteBuffer we should use
                if (b == Buffer && 0 == offset)
                {
                    // Use our own pre-wrapped byteBuf:
                    Debug.Assert(ByteBuf != null);
                    ByteBuf.Clear();
                    ByteBuf.Limit = len;
                    bb = ByteBuf;
                }
                else
                {
                    bb = ByteBuffer.Wrap((byte[])(Array)b, offset, len);
                }

                int readOffset = bb.Position;
                int readLength = bb.Limit - readOffset;
                long pos = FilePointer + Off;

                if (pos + len > End)
                {
                    throw new EndOfStreamException("read past EOF: " + this);
                }

                try
                {
                    while (readLength > 0)
                    {
                        int limit;
                        if (readLength > CHUNK_SIZE)
                        {
                            limit = readOffset + CHUNK_SIZE;
                        }
                        else
                        {
                            limit = readOffset + readLength;
                        }
                        bb.Limit = limit;
                        int i = Channel.Read(bb, pos);
                        if (i <= 0) // be defensive here, even though we checked before hand, something could have changed
                        {
                            throw new Exception("read past EOF: " + this + " off: " + offset + " len: " + len + " pos: " + pos + " chunkLen: " + readLength + " end: " + End);
                        }
                        pos += i;
                        readOffset += i;
                        readLength -= i;
                    }
                    Debug.Assert(readLength == 0);
                }
                catch (System.IO.IOException ioe)
                {
                    throw new System.IO.IOException(ioe.Message + ": " + this, ioe);
                }
            }