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/10/31 21:13:05 UTC
[lucenenet] 04/04: Lucene.Net.Util.OfflineSorter (ByteSequencesReader + ByteSequencesWriter): Added constructor overloads to pass the file name as a string (.NET convention)
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
commit a2b4c31195f18bdfc7592ff86a1dbe3ceed2a9f1
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Tue Nov 1 00:16:26 2022 +0700
Lucene.Net.Util.OfflineSorter (ByteSequencesReader + ByteSequencesWriter): Added constructor overloads to pass the file name as a string (.NET convention)
---
src/Lucene.Net/Util/OfflineSorter.cs | 38 ++++++++++++++++++++++++++++++++----
1 file changed, 34 insertions(+), 4 deletions(-)
diff --git a/src/Lucene.Net/Util/OfflineSorter.cs b/src/Lucene.Net/Util/OfflineSorter.cs
index 333d340b3..afd208770 100644
--- a/src/Lucene.Net/Util/OfflineSorter.cs
+++ b/src/Lucene.Net/Util/OfflineSorter.cs
@@ -554,6 +554,14 @@ namespace Lucene.Net.Util
{
}
+ /// <summary>
+ /// Constructs a <see cref="ByteSequencesWriter"/> to the provided <see cref="FileInfo"/>. </summary>
+ /// <exception cref="ArgumentException"><paramref name="path"/> is <c>null</c> or whitespace.</exception>
+ public ByteSequencesWriter(string path)
+ : this(NewBinaryWriterDataOutput(path))
+ {
+ }
+
/// <summary>
/// Constructs a <see cref="ByteSequencesWriter"/> to the provided <see cref="DataOutput"/>. </summary>
/// <exception cref="ArgumentNullException"><paramref name="os"/> is <c>null</c>.</exception>
@@ -573,15 +581,28 @@ namespace Lucene.Net.Util
if (file is null)
throw new ArgumentNullException(nameof(file));
- string fileName = file.FullName;
+ return NewBinaryWriterDataOutput(file.FullName);
+ }
+
+ /// <summary>
+ /// LUCENENET specific - ensures the file has been created with no BOM
+ /// if it doesn't already exist and opens the file for writing.
+ /// Java doesn't use a BOM by default.
+ /// </summary>
+ /// <exception cref="ArgumentException"><paramref name="path"/> is <c>null</c> or whitespace.</exception>
+ private static BinaryWriterDataOutput NewBinaryWriterDataOutput(string path)
+ {
+ if (string.IsNullOrWhiteSpace(path))
+ throw new ArgumentException($"{nameof(path)} may not be null or whitespace.");
+
// Create the file (without BOM) if it doesn't already exist
- if (!File.Exists(fileName))
+ if (!File.Exists(path))
{
// Create the file
- File.WriteAllText(fileName, string.Empty, new UTF8Encoding(false) /* No BOM */);
+ File.WriteAllText(path, string.Empty, new UTF8Encoding(false) /* No BOM */);
}
- return new BinaryWriterDataOutput(new BinaryWriter(new FileStream(fileName, FileMode.Open, FileAccess.Write)));
+ return new BinaryWriterDataOutput(new BinaryWriter(new FileStream(path, FileMode.Open, FileAccess.Write)));
}
/// <summary>
@@ -673,6 +694,15 @@ namespace Lucene.Net.Util
{
}
+ /// <summary>
+ /// Constructs a <see cref="ByteSequencesReader"/> from the provided <paramref name="path"/>. </summary>
+ /// <exception cref="ArgumentException"><paramref name="path"/> is <c>null</c> or whitespace.</exception>
+ // LUCENENET specific
+ public ByteSequencesReader(string path)
+ : this(!string.IsNullOrWhiteSpace(path) ? new FileInfo(path) : throw new ArgumentException($"{nameof(path)} may not be null or whitespace."))
+ {
+ }
+
/// <summary>
/// Constructs a <see cref="ByteSequencesReader"/> from the provided <see cref="DataInput"/>. </summary>
/// <exception cref="ArgumentNullException"><paramref name="inputStream"/> is <c>null</c>.</exception>