Skip to content

Commit

Permalink
Use Encoding.Default instead of GetEncoding(0), #1076
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirwin committed Jan 11, 2025
1 parent d2c4b52 commit 66f3e3c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/Lucene.Net.Benchmark/ByTask/Feeds/ContentItemsSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ namespace Lucene.Net.Benchmarks.ByTask.Feeds
/// Base class for source of data for benchmarking.
/// </summary>
/// <remarks>
/// Keeps track of various statistics, such as how many data items were generated,
/// Keeps track of various statistics, such as how many data items were generated,
/// size in bytes etc.
/// <para/>
/// Supports the following configuration parameters:
/// <list type="bullet">
/// <item><term>content.source.forever</term><description>specifies whether to generate items forever (<b>default=true</b>).</description></item>
/// <item><term>content.source.verbose</term><description>specifies whether messages should be output by the content source (<b>default=false</b>).</description></item>
/// <item><term>content.source.encoding</term><description>
/// specifies which encoding to use when
/// specifies which encoding to use when
/// reading the files of that content source. Certain implementations may define
/// a default value if this parameter is not specified. (<b>default=null</b>).
/// </description></item>
Expand Down Expand Up @@ -199,7 +199,7 @@ public virtual void SetConfig(Config config)
}
else
{
m_encoding = Encoding.GetEncoding(0); // Default system encoding
m_encoding = Encoding.Default; // Default system encoding
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Lucene.Net.Benchmark/ByTask/Tasks/CreateIndexTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static IndexWriter ConfigureWriter(Config config, PerfRunData runData, Op
else
{
FileInfo f = new FileInfo(infoStreamVal);
iwc.SetInfoStream(new StreamWriter(new FileStream(f.FullName, FileMode.Create, FileAccess.Write), Encoding.GetEncoding(0)));
iwc.SetInfoStream(new StreamWriter(new FileStream(f.FullName, FileMode.Create, FileAccess.Write), Encoding.Default));
}
}
IndexWriter writer = new IndexWriter(runData.Directory, iwc);
Expand Down
9 changes: 6 additions & 3 deletions src/Lucene.Net.Benchmark/Quality/Trec/QueryDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ public static void Main(string[] args)
string fieldSpec = args.Length == 5 ? args[4] : "T"; // default to Title-only if not specified.
IndexSearcher searcher = new IndexSearcher(reader);

int maxResults = 1000;
string docNameField = "docname";
const int maxResults = 1000;
const string docNameField = "docname";

TextWriter logger = Console.Out; //new StreamWriter(Console, Encoding.GetEncoding(0));
using TextWriter logger = new StreamWriter(System.Console.OpenStandardOutput(), Encoding.Default)
{
AutoFlush = true,
};

// use trec utilities to read trec topics into quality queries
TrecTopicsReader qReader = new TrecTopicsReader();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void TestInfoStream_SystemOutErr()

TextWriter curOut = Console.Out;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Console.Out = new StreamWriter(baos, Encoding.GetEncoding(0));
Console.Out = new StreamWriter(baos, Encoding.Default);
try
{
PerfRunData runData = createPerfRunData("SystemOut");
Expand All @@ -72,7 +72,7 @@ public void TestInfoStream_SystemOutErr()

TextWriter curErr = Console.Error;
baos = new ByteArrayOutputStream();
Console.Error = new StreamWriter(baos, Encoding.GetEncoding(0));
Console.Error = new StreamWriter(baos, Encoding.Default);
try
{
PerfRunData runData = createPerfRunData("SystemErr");
Expand Down
6 changes: 2 additions & 4 deletions src/Lucene.Net.Tests.Demo/TestDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ private void TestOneSearch(DirectoryInfo indexPath, string query, int expectedHi
try
{
MemoryStream bytes = new MemoryStream();
// .NET NOTE: GetEncoding(0) returns the current system's default encoding
var fakeSystemOut = new StreamWriter(bytes, Encoding.GetEncoding(0));
var fakeSystemOut = new StreamWriter(bytes, Encoding.Default);
Console.SetOut(fakeSystemOut);
// LUCENENET specific: changed the arguments to act more like the dotnet.exe commands.
// * only optional arguments start with -
Expand All @@ -44,8 +43,7 @@ private void TestOneSearch(DirectoryInfo indexPath, string query, int expectedHi
// it consistent with the lucene-cli utility.
SearchFiles.Main(new string[] { indexPath.FullName, "--query", query });
fakeSystemOut.Flush();
// .NET NOTE: GetEncoding(0) returns the current system's default encoding
string output = Encoding.GetEncoding(0).GetString(bytes.ToArray()); // intentionally use default encoding
string output = Encoding.Default.GetString(bytes.ToArray()); // intentionally use default encoding
assertTrue("output=" + output, output.Contains(expectedHitCount + " total matching documents"));
}
finally
Expand Down

0 comments on commit 66f3e3c

Please sign in to comment.