You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2022/11/22 13:19:07 UTC
[lucenenet] branch master updated: Align InputStreamDataInput and OutputStreamDataOutput closer to the Java Source (#769)
This is an automated email from the ASF dual-hosted git repository.
nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git
The following commit(s) were added to refs/heads/master by this push:
new dfbb22218 Align InputStreamDataInput and OutputStreamDataOutput closer to the Java Source (#769)
dfbb22218 is described below
commit dfbb22218becd21f111cb711ae290fc119944432
Author: Jens Melgaard <ad...@it-links.dk>
AuthorDate: Tue Nov 22 14:19:01 2022 +0100
Align InputStreamDataInput and OutputStreamDataOutput closer to the Java Source (#769)
* Fixed InputStreamDataInput and OutputStreamDataOutput so that they don't wrap their input streams to BinaryReader/Writers to align the code closer to the Java source.
* Added comments for Lucene.net specifc code and null check.
---
src/Lucene.Net/Store/InputStreamDataInput.cs | 23 +++++++----------------
src/Lucene.Net/Store/OutputStreamDataOutput.cs | 13 ++++++-------
2 files changed, 13 insertions(+), 23 deletions(-)
diff --git a/src/Lucene.Net/Store/InputStreamDataInput.cs b/src/Lucene.Net/Store/InputStreamDataInput.cs
index d3b804019..b9462397a 100644
--- a/src/Lucene.Net/Store/InputStreamDataInput.cs
+++ b/src/Lucene.Net/Store/InputStreamDataInput.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
namespace Lucene.Net.Store
@@ -25,16 +25,16 @@ namespace Lucene.Net.Store
/// </summary>
public class InputStreamDataInput : DataInput, IDisposable
{
- private BinaryReader _reader;
+ private readonly Stream _is;
public InputStreamDataInput(Stream @is)
{
- this._reader = new BinaryReader(@is);
+ this._is = @is ?? throw new ArgumentNullException(nameof(@is)); // LUCENENET specific - added null guard clause
}
public override byte ReadByte()
{
- int v = _reader.ReadByte();
+ int v = _is.ReadByte();
if (v == -1)
{
throw EOFException.Create();
@@ -46,7 +46,7 @@ namespace Lucene.Net.Store
{
while (len > 0)
{
- int cnt = _reader.Read(b, offset, len);
+ int cnt = _is.Read(b, offset, len);
if (cnt < 0)
{
// Partially read the input, but no more data available in the stream.
@@ -60,23 +60,14 @@ namespace Lucene.Net.Store
public void Dispose()
{
Dispose(true);
-
GC.SuppressFinalize(this);
}
- private bool disposed = false;
-
protected virtual void Dispose(bool disposing)
{
- if (!disposed)
+ if (disposing)
{
- if (disposing)
- {
- _reader.Dispose();
- }
-
- _reader = null;
- disposed = true;
+ _is.Dispose();
}
}
}
diff --git a/src/Lucene.Net/Store/OutputStreamDataOutput.cs b/src/Lucene.Net/Store/OutputStreamDataOutput.cs
index f6629ae1b..f635a2b36 100644
--- a/src/Lucene.Net/Store/OutputStreamDataOutput.cs
+++ b/src/Lucene.Net/Store/OutputStreamDataOutput.cs
@@ -1,4 +1,4 @@
-using System;
+using System;
using System.IO;
namespace Lucene.Net.Store
@@ -25,21 +25,21 @@ namespace Lucene.Net.Store
/// </summary>
public class OutputStreamDataOutput : DataOutput, IDisposable
{
- private readonly BinaryWriter _writer;
+ private readonly Stream _os;
public OutputStreamDataOutput(Stream os)
{
- this._writer = new BinaryWriter(os);
+ this._os = os ?? throw new ArgumentNullException(nameof(os)); // LUCENENET specific - added null guard clause
}
public override void WriteByte(byte b)
{
- _writer.Write(b);
+ _os.WriteByte(b);
}
public override void WriteBytes(byte[] b, int offset, int length)
{
- _writer.Write(b, offset, length);
+ _os.Write(b, offset, length);
}
/// <summary>
@@ -57,13 +57,12 @@ namespace Lucene.Net.Store
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources;
/// <c>false</c> to release only unmanaged resources.</param>
-
// LUCENENET specific - implemented proper dispose pattern
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
- _writer.Dispose();
+ _os.Dispose();
}
}
}