public override int Read(byte[] buffer, int offset, int count) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } if ((uint)offset > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.offset); } if ((uint)count > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.count); } if ((uint)buffer.Length < (uint)(offset + count)) { ThrowHelper.ThrowArgumentException_InvalidOffLen(); } EnsureNotClosed(); int read = Math.Min(count, _buffer.ReadableBytes); if (0u >= (uint)read) { return(0); } _ = _buffer.ReadBytes(buffer, offset, read); return(read); }
public override int Read(byte[] buffer, int offset, int count) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } if (offset < 0) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.offset); } if (count < 0) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.count); } if (buffer.Length - offset < count) { ThrowHelper.ThrowArgumentException_InvalidOffLen(); } EnsureNotClosed(); int read = Math.Min(count, _buffer.ReadableBytes); if (0u >= (uint)read) { return(0); } _ = _buffer.ReadBytes(buffer, offset, read); return(read); }
public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } if ((uint)offset > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.offset); } if ((uint)count > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.count); } if ((uint)buffer.Length < (uint)(offset + count)) { ThrowHelper.ThrowArgumentException_InvalidOffLen(); } EnsureNotClosed(); EnsureWriteable(); // If cancellation is already requested, bail early if (cancellationToken.IsCancellationRequested) { return(TaskUtil.FromCanceled(cancellationToken)); } try { _ = _buffer.WriteBytes(buffer, offset, count); return(TaskUtil.Completed); } //catch (OperationCanceledException oce) //{ // return Task.FromCancellation<VoidTaskResult>(oce); //} catch (Exception exception) { return(TaskUtil.FromException(exception)); } }
public override void Write(byte[] buffer, int offset, int count) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } if ((uint)offset > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.offset); } if ((uint)count > SharedConstants.TooBigOrNegative) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.count); } if ((uint)buffer.Length < (uint)(offset + count)) { ThrowHelper.ThrowArgumentException_InvalidOffLen(); } EnsureNotClosed(); EnsureWriteable(); _ = _buffer.WriteBytes(buffer, offset, count); }
public override void Write(byte[] buffer, int offset, int count) { if (buffer is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer); } if (offset < 0) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.offset); } if (count < 0) { ThrowHelper.ThrowArgumentOutOfRangeException_NeedNonNegNum(ExceptionArgument.count); } if (buffer.Length - offset < count) { ThrowHelper.ThrowArgumentException_InvalidOffLen(); } EnsureNotClosed(); EnsureWriteable(); _ = _buffer.WriteBytes(buffer, offset, count); }