public long IndexOf(byte b, long fromIndex, long toIndex) { if (_closed) { throw new IllegalStateException("closed"); } if (fromIndex < 0 || toIndex < fromIndex) { throw new ArgumentException( string.Format("fromIndex=%s toIndex=%s", fromIndex, toIndex)); } while (fromIndex < toIndex) { long result = _easyBuffer.IndexOf(b, fromIndex, toIndex); if (result != -1L) { return(result); } // The byte wasn't in the buffer. Give up if we've already reached our target size or if the // underlying stream is exhausted. long lastBufferSize = _easyBuffer.Size; if (lastBufferSize >= toIndex || _source.Read(_easyBuffer, Segment.SIZE) == -1) { return(-1L); } // Continue the search from where we left off. fromIndex = Math.Max(fromIndex, lastBufferSize); } return(-1L); }