NightOwl888 commented on code in PR #1195:
URL: https://github.com/apache/lucenenet/pull/1195#discussion_r2392761963
##########
src/Lucene.Net/Support/IO/StreamExtensions.cs:
##########
@@ -68,51 +71,38 @@ internal static class StreamExtensions
/// <exception cref="IOException">An I/O error occurs.</exception>
/// <exception cref="ObjectDisposedException"><paramref
name="stream"/> has already been disposed.</exception>
/// <remarks>
- /// This method is atomic when used by itself, but does not
synchronize with the rest of the stream methods.
+ /// On .NET 6+, this method uses the RandomAccess class to
synchronize, so it is completely threadsafe
+ /// and does not require the stream to be seekable or readable.
+ /// <para/>
+ /// On older target frameworks, this method is atomic when used by
itself, but does not synchronize with
+ /// the rest of the stream methods.
/// </remarks>
- public static int Read(this Stream stream, ByteBuffer destination,
long position)
+ public static int Read(this FileStream stream, Span<byte> destination,
long position)
{
if (stream is null)
throw new ArgumentNullException(nameof(stream));
- if (destination is null)
- throw new ArgumentNullException(nameof(destination));
if (position < 0)
throw new ArgumentOutOfRangeException(nameof(position));
+ if (position > stream.Length)
Review Comment:
If `CanSeek` is `false`, this check will throw. So, this will need to be
moved to the #else block. `RandomAccess.Read()` should correctly return 0 in
this case without having to check the length.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]