Skip to content

Commit

Permalink
IDisposable Pattern Cleanup, #265
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 12, 2025
1 parent 24fb64b commit 9473cbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,8 @@ private void ReadDictionaryFiles(IList<Stream> dictionaries, Encoding decoder, B
{
foreach (Stream dictionary in dictionaries)
{
using var lines = new StreamReader(dictionary, decoder); // LUCENENET specific - CA2000: Use using pattern to ensure reader is disposed
// LUCENENET specific - CA2000: Use using pattern to ensure reader is disposed, although we want to leave the dictionary stream open. See: TestDictionary.TestResourceCleanup
using var lines = new StreamReader(dictionary, decoder, detectEncodingFromByteOrderMarks: true, bufferSize: -1, leaveOpen: true);
string line = lines.ReadLine(); // first line is number of entries (approximately, sometimes)

while ((line = lines.ReadLine()) != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ IEnumerator IEnumerable.GetEnumerator()
}

// per-document vint-encoded byte[]
internal class SortedSetEnumerator : IEnumerator<BytesRef>
internal sealed class SortedSetEnumerator : IEnumerator<BytesRef>
{
internal byte[] buffer = new byte[10];
internal ByteArrayDataOutput @out = new ByteArrayDataOutput();
Expand Down Expand Up @@ -426,7 +426,7 @@ public bool MoveNext()
object IEnumerator.Current => Current;

// encodes count values to buffer
internal virtual void EncodeValues(int count)
internal void EncodeValues(int count)
{
@out.Reset(buffer);
long lastOrd = 0;
Expand All @@ -450,4 +450,4 @@ public void Dispose()
}
}
#pragma warning restore 612, 618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,18 @@ public override long Position
set => @delegate.Position = value;
}

public CloseCheckInputStream(TestDictionary outerInstance, System.IO.Stream @delegate)
public CloseCheckInputStream(TestDictionary outerInstance, System.IO.Stream @delegate)
{
this.@delegate = @delegate;
this.outerInstance = outerInstance;
}

protected override void Dispose(bool disposing)
{
disposed = true;
@delegate.Dispose();
}


new public void Dispose()
{
this.disposed = true;
base.Dispose();
}


public virtual bool Disposed => this.disposed;

public override void Flush()
Expand Down Expand Up @@ -209,7 +202,7 @@ public virtual void TestResourceCleanup()
CloseCheckInputStream affixStream = new CloseCheckInputStream(this, this.GetType().getResourceAsStream("compressed.aff"));
CloseCheckInputStream dictStream = new CloseCheckInputStream(this, this.GetType().getResourceAsStream("compressed.dic"));

new Dictionary(affixStream, dictStream);
_ = new Dictionary(affixStream, dictStream);

assertFalse(affixStream.Disposed);
assertFalse(dictStream.Disposed);
Expand Down Expand Up @@ -289,4 +282,4 @@ public virtual void TestFlagWithCrazyWhitespace()
assertNotNull(Dictionary.GetFlagParsingStrategy("FLAG UTF-8"));
}
}
}
}

0 comments on commit 9473cbe

Please sign in to comment.