Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDisposable Pattern Cleanup and fix TestDictionary.TestResourceCleanup, #265 #1095

Merged
merged 2 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 1024, 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"));
}
}
}
}
Loading