lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From synhers...@apache.org
Subject [5/5] lucenenet git commit: Bring ByteSequencesWriter back in
Date Mon, 10 Nov 2014 15:25:27 GMT
Bring ByteSequencesWriter back in


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ee575336
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ee575336
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ee575336

Branch: refs/heads/master
Commit: ee575336c5322b926cef2ddc4d556eb5b0709828
Parents: 139ad81
Author: Itamar Syn-Hershko <itamar@code972.com>
Authored: Mon Nov 10 17:25:17 2014 +0200
Committer: Itamar Syn-Hershko <itamar@code972.com>
Committed: Mon Nov 10 17:25:17 2014 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj           |   1 +
 .../Compatibility/BinaryWriterDataOutput.cs     |  31 +++++
 src/Lucene.Net.Core/Util/OfflineSorter.cs       | 134 ++++++++++---------
 3 files changed, 100 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee575336/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj
index 58a6c8a..1e8b3a0 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -617,6 +617,7 @@
     <Compile Include="Support\ByteBuffer.cs" />
     <Compile Include="Support\Character.cs" />
     <Compile Include="Support\Arrays.cs" />
+    <Compile Include="Support\Compatibility\BinaryWriterDataOutput.cs" />
     <Compile Include="Support\Compatibility\Collections.cs" />
     <Compile Include="Support\ConcurrentHashMap.cs" />
     <Compile Include="Support\ConcurrentHashMapWrapper.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee575336/src/Lucene.Net.Core/Support/Compatibility/BinaryWriterDataOutput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Compatibility/BinaryWriterDataOutput.cs b/src/Lucene.Net.Core/Support/Compatibility/BinaryWriterDataOutput.cs
new file mode 100644
index 0000000..31e5b07
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Compatibility/BinaryWriterDataOutput.cs
@@ -0,0 +1,31 @@
+´╗┐using System;
+using System.IO;
+using Lucene.Net.Store;
+
+namespace Lucene.Net.Support.Compatibility
+{
+    public class BinaryWriterDataOutput : DataOutput, IDisposable
+    {
+        private readonly BinaryWriter bw;
+
+        public BinaryWriterDataOutput(BinaryWriter bw)
+        {
+            this.bw = bw;
+        }
+
+        public override void WriteByte(byte b)
+        {
+            bw.Write(b);
+        }
+
+        public override void WriteBytes(byte[] b, int offset, int length)
+        {
+            bw.Write(b, offset, length);
+        }
+
+        public void Dispose()
+        {
+            bw.Dispose();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ee575336/src/Lucene.Net.Core/Util/OfflineSorter.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/OfflineSorter.cs b/src/Lucene.Net.Core/Util/OfflineSorter.cs
index 4f72585..db6db48 100644
--- a/src/Lucene.Net.Core/Util/OfflineSorter.cs
+++ b/src/Lucene.Net.Core/Util/OfflineSorter.cs
@@ -2,6 +2,8 @@ using System;
 using System.Collections.Generic;
 using System.Diagnostics;
 using System.IO;
+using Lucene.Net.Store;
+using Lucene.Net.Support.Compatibility;
 
 namespace Lucene.Net.Util
 {
@@ -512,72 +514,72 @@ namespace Lucene.Net.Util
 //            }
 //        }
 //
-//        /// <summary>
-//        /// Utility class to emit length-prefixed byte[] entries to an output stream for
sorting.
-//        /// Complementary to <seealso cref="ByteSequencesReader"/>.
-//        /// </summary>
-//        public class ByteSequencesWriter : IDisposable
-//        {
-//            internal readonly DataOutput Os;
-//
-//            /// <summary>
-//            /// Constructs a ByteSequencesWriter to the provided File </summary>
-//            public ByteSequencesWriter(FileInfo file)
-//                : this(new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))))
-//            {
-//            }
-//
-//            /// <summary>
-//            /// Constructs a ByteSequencesWriter to the provided DataOutput </summary>
-//            public ByteSequencesWriter(DataOutput os)
-//            {
-//                this.Os = os;
-//            }
-//
-//            /// <summary>
-//            /// Writes a BytesRef. </summary>
-//            /// <seealso cref= #write(byte[], int, int) </seealso>
-//            public virtual void Write(BytesRef @ref)
-//            {
-//                Debug.Assert(@ref != null);
-//                Write(@ref.Bytes, @ref.Offset, @ref.Length);
-//            }
-//
-//            /// <summary>
-//            /// Writes a byte array. </summary>
-//            /// <seealso cref= #write(byte[], int, int) </seealso>
-//            public virtual void Write(sbyte[] bytes)
-//            {
-//                Write(bytes, 0, bytes.Length);
-//            }
-//
-//            /// <summary>
-//            /// Writes a byte array.
-//            /// <p>
-//            /// The length is written as a <code>short</code>, followed
-//            /// by the bytes.
-//            /// </summary>
-//            public virtual void Write(sbyte[] bytes, int off, int len)
-//            {
-//                Debug.Assert(bytes != null);
-//                Debug.Assert(off >= 0 && off + len <= bytes.Length);
-//                Debug.Assert(len >= 0);
-//                Os.WriteShort(len);
-//                Os.Write(bytes, off, len);
-//            }
-//
-//            /// <summary>
-//            /// Closes the provided <seealso cref="DataOutput"/> if it is <seealso
cref="IDisposable"/>.
-//            /// </summary>
-//            public void Dispose()
-//            {
-//                var os = Os as IDisposable;
-//                if (os != null)
-//                {
-//                    os.Dispose();
-//                }
-//            }
-//        }
+        /// <summary>
+        /// Utility class to emit length-prefixed byte[] entries to an output stream for
sorting.
+        /// Complementary to <seealso cref="ByteSequencesReader"/>.
+        /// </summary>
+        public class ByteSequencesWriter : IDisposable
+        {
+            internal readonly DataOutput Os;
+
+            /// <summary>
+            /// Constructs a ByteSequencesWriter to the provided File </summary>
+            public ByteSequencesWriter(string filePath)
+                : this(new BinaryWriterDataOutput(new BinaryWriter(new FileStream(filePath,
FileMode.Open))))
+            {
+            }
+
+            /// <summary>
+            /// Constructs a ByteSequencesWriter to the provided DataOutput </summary>
+            public ByteSequencesWriter(DataOutput os)
+            {
+                this.Os = os;
+            }
+
+            /// <summary>
+            /// Writes a BytesRef. </summary>
+            /// <seealso cref= #write(byte[], int, int) </seealso>
+            public virtual void Write(BytesRef @ref)
+            {
+                Debug.Assert(@ref != null);
+                Write(@ref.Bytes, @ref.Offset, @ref.Length);
+            }
+
+            /// <summary>
+            /// Writes a byte array. </summary>
+            /// <seealso cref= #write(byte[], int, int) </seealso>
+            public virtual void Write(byte[] bytes)
+            {
+                Write(bytes, 0, bytes.Length);
+            }
+
+            /// <summary>
+            /// Writes a byte array.
+            /// <p>
+            /// The length is written as a <code>short</code>, followed
+            /// by the bytes.
+            /// </summary>
+            public virtual void Write(byte[] bytes, int off, int len)
+            {
+                Debug.Assert(bytes != null);
+                Debug.Assert(off >= 0 && off + len <= bytes.Length);
+                Debug.Assert(len >= 0);
+                Os.WriteShort((short)len);
+                Os.Write(bytes, off, len);
+            }
+
+            /// <summary>
+            /// Closes the provided <seealso cref="DataOutput"/> if it is <seealso
cref="IDisposable"/>.
+            /// </summary>
+            public void Dispose()
+            {
+                var os = Os as IDisposable;
+                if (os != null)
+                {
+                    os.Dispose();
+                }
+            }
+        }
 //
 //        /// <summary>
 //        /// Utility class to read length-prefixed byte[] entries from an input.


Mime
View raw message