lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [09/45] lucenenet git commit: Ported ByteBuffer, LongBuffer, and other Buffer-related types from the Apache Harmony project (since the OpenJDK has a license that is off-limits)
Date Sun, 30 Apr 2017 21:55:48 GMT
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net.Tests/Support/TestLongBuffer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Support/TestLongBuffer.cs b/src/Lucene.Net.Tests/Support/TestLongBuffer.cs
deleted file mode 100644
index ffde715..0000000
--- a/src/Lucene.Net.Tests/Support/TestLongBuffer.cs
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
-*/
-
-using Lucene.Net.Attributes;
-using NUnit.Framework;
-using System;
-using System.Reflection;
-
-namespace Lucene.Net.Support
-{
-    /// <summary>
-    /// Tests from JDK/nio/BasicLong.java
-    /// </summary>
-    public class TestLongBuffer : BaseBufferTestCase
-    {
-        private static readonly long[] VALUES = {
-            long.MinValue,
-            (long) -1,
-            (long) 0,
-            (long) 1,
-            long.MaxValue,
-        };
-
-
-        private static void relGet(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            //long v; // LUCENENET: Not used
-            for (int i = 0; i < n; i++)
-                ck(b, (long)b.Get(), (long)((long)Ic(i)));
-            b.Rewind();
-        }
-
-        private static void relGet(Int64Buffer b, int start)
-        {
-            int n = b.Remaining;
-            //long v; // LUCENENET: Not used
-            for (int i = start; i < n; i++)
-                ck(b, (long)b.Get(), (long)((long)Ic(i)));
-            b.Rewind();
-        }
-
-        private static void absGet(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            //long v; // LUCENENET: Not used
-            for (int i = 0; i < n; i++)
-                ck(b, (long)b.Get(), (long)((long)Ic(i)));
-            b.Rewind();
-        }
-
-        private static void bulkGet(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            long[] a = new long[n + 7];
-            b.Get(a, 7, n);
-            for (int i = 0; i < n; i++)
-                ck(b, (long)a[i + 7], (long)((long)Ic(i)));
-        }
-
-        private static void relPut(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            for (int i = 0; i < n; i++)
-                b.Put((long)Ic(i));
-            b.Flip();
-        }
-
-        private static void absPut(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            for (int i = 0; i < n; i++)
-                b.Put(i, (long)Ic(i));
-            b.Limit = (n);
-            b.Position = (0);
-        }
-
-        private static void bulkPutArray(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            long[] a = new long[n + 7];
-            for (int i = 0; i < n; i++)
-                a[i + 7] = (long)Ic(i);
-            b.Put(a, 7, n);
-            b.Flip();
-        }
-
-        private static void bulkPutBuffer(Int64Buffer b)
-        {
-            int n = b.Capacity;
-            b.Clear();
-            Int64Buffer c = Int64Buffer.Allocate(n + 7);
-            c.Position = (7);
-            for (int i = 0; i < n; i++)
-                c.Put((long)Ic(i));
-            c.Flip();
-            c.Position = (7);
-            b.Put(c);
-            b.Flip();
-        }
-
-        //6231529
-        private static void callReset(Int64Buffer b)
-        {
-            b.Position = (0);
-            b.Mark();
-
-            b.Duplicate().Reset();
-
-            // LUCENENET: AsReadOnlyBuffer() not implemented
-            //b.AsReadOnlyBuffer().Reset();
-        }
-
-
-
-        // 6221101-6234263
-
-        private static void putBuffer()
-        {
-            int cap = 10;
-
-            // LUCENENET: AllocateDirect not implemented
-
-            //LongBuffer direct1 = ByteBuffer.AllocateDirect(cap).AsLongBuffer();
-            Int64Buffer nondirect1 = ByteBuffer.Allocate(cap).AsInt64Buffer();
-            //direct1.Put(nondirect1);
-
-            //LongBuffer direct2 = ByteBuffer.AllocateDirect(cap).AsLongBuffer();
-            Int64Buffer nondirect2 = ByteBuffer.Allocate(cap).AsInt64Buffer();
-            //nondirect2.Put(direct2);
-
-            //LongBuffer direct3 = ByteBuffer.AllocateDirect(cap).AsLongBuffer();
-            //LongBuffer direct4 = ByteBuffer.AllocateDirect(cap).AsLongBuffer();
-            //direct3.Put(direct4);
-
-            Int64Buffer nondirect3 = ByteBuffer.Allocate(cap).AsInt64Buffer();
-            Int64Buffer nondirect4 = ByteBuffer.Allocate(cap).AsInt64Buffer();
-            nondirect3.Put(nondirect4);
-        }
-
-        private static void checkSlice(Int64Buffer b, Int64Buffer slice)
-        {
-            ck(slice, 0, slice.Position);
-            ck(slice, b.Remaining, slice.Limit);
-            ck(slice, b.Remaining, slice.Capacity);
-            if (b.IsDirect != slice.IsDirect)
-                fail("Lost direction", slice);
-            if (b.IsReadOnly != slice.IsReadOnly)
-                fail("Lost read-only", slice);
-        }
-
-        private static void fail(string problem,
-                                 Int64Buffer xb, Int64Buffer yb,
-                                 long x, long y)
-        {
-            fail(problem + string.Format(": x={0} y={1}", x, y), xb, yb);
-        }
-
-        private static void tryCatch(Buffer b, Type ex, Action thunk)
-        {
-            bool caught = false;
-            try
-            {
-                thunk();
-            }
-            catch (Exception x)
-            {
-                if (ex.GetTypeInfo().IsAssignableFrom(x.GetType()))
-                {
-                    caught = true;
-                }
-                else
-                {
-                    fail(x.Message + " not expected");
-                }
-            }
-            if (!caught)
-                fail(ex.Name + " not thrown", b);
-        }
-
-        private static void tryCatch(long[] t, Type ex, Action thunk)
-        {
-            tryCatch(Int64Buffer.Wrap(t), ex, thunk);
-        }
-
-        public static void test(int level, Int64Buffer b, bool direct)
-        {
-
-            Show(level, b);
-
-            if (direct != b.IsDirect)
-                fail("Wrong direction", b);
-
-            // Gets and puts
-
-            relPut(b);
-            relGet(b);
-            absGet(b);
-            bulkGet(b);
-
-            absPut(b);
-            relGet(b);
-            absGet(b);
-            bulkGet(b);
-
-            bulkPutArray(b);
-            relGet(b);
-
-            bulkPutBuffer(b);
-            relGet(b);
-
-            // Compact
-
-            relPut(b);
-            b.Position = (13);
-            b.Compact();
-            b.Flip();
-            relGet(b, 13);
-
-            // Exceptions
-
-            relPut(b);
-            b.Limit = (b.Capacity / 2);
-            b.Position = (b.Limit);
-
-            tryCatch(b, typeof(BufferUnderflowException), () =>
-            {
-                b.Get();
-            });
-
-            tryCatch(b, typeof(BufferOverflowException), () =>
-            {
-                b.Put((long)42);
-            });
-
-            // The index must be non-negative and lesss than the buffer's limit.
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
-            {
-                b.Get(b.Limit);
-            });
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
-            {
-                b.Get(-1);
-            });
-
-            tryCatch(b, typeof(IndexOutOfRangeException), () =>
-            {
-                b.Put(b.Limit, (long)42);
-            });
-
-            tryCatch(b, typeof(InvalidMarkException), () =>
-            {
-                b.Position = (0);
-                b.Mark();
-                b.Compact();
-                b.Reset();
-            });
-
-            // Values
-
-            b.Clear();
-            b.Put((long)0);
-            b.Put((long)-1);
-            b.Put((long)1);
-            b.Put(long.MaxValue);
-            b.Put(long.MinValue);
-
-            //long v; // LUCENENET: Not used
-            b.Flip();
-            ck(b, b.Get(), 0);
-            ck(b, b.Get(), (long)-1);
-            ck(b, b.Get(), 1);
-            ck(b, b.Get(), long.MaxValue);
-            ck(b, b.Get(), long.MinValue);
-
-
-            // Comparison
-            b.Rewind();
-            Int64Buffer b2 = Lucene.Net.Support.Int64Buffer.Allocate(b.Capacity);
-            b2.Put(b);
-            b2.Flip();
-            b.Position = (2);
-            b2.Position = (2);
-            if (!b.equals(b2))
-            {
-                for (int i = 2; i < b.Limit; i++)
-                {
-                    long x = b.Get(i);
-                    long y = b2.Get(i);
-                    if (x != y)
-                        output.WriteLine("[" + i + "] " + x + " != " + y);
-                }
-                fail("Identical buffers not equal", b, b2);
-            }
-            if (b.CompareTo(b2) != 0)
-                fail("Comparison to identical buffer != 0", b, b2);
-
-            b.Limit = (b.Limit + 1);
-            b.Position = (b.Limit - 1);
-            b.Put((long)99);
-            b.Rewind();
-            b2.Rewind();
-            if (b.Equals(b2))
-                fail("Non-identical buffers equal", b, b2);
-            if (b.CompareTo(b2) <= 0)
-                fail("Comparison to shorter buffer <= 0", b, b2);
-            b.Limit = (b.Limit - 1);
-
-            b.Put(2, (long)42);
-            if (b.equals(b2))
-                fail("Non-identical buffers equal", b, b2);
-            if (b.CompareTo(b2) <= 0)
-                fail("Comparison to lesser buffer <= 0", b, b2);
-
-            // Check equals and compareTo with interesting values
-            foreach (long x in VALUES)
-            {
-                Int64Buffer xb = Lucene.Net.Support.Int64Buffer.Wrap(new long[] { x });
-                if (xb.CompareTo(xb) != 0)
-                {
-                    fail("compareTo not reflexive", xb, xb, x, x);
-                }
-                if (!xb.equals(xb))
-                {
-                    fail("equals not reflexive", xb, xb, x, x);
-                }
-                foreach (long y in VALUES)
-                {
-                    Int64Buffer yb = Lucene.Net.Support.Int64Buffer.Wrap(new long[] { y });
-                    if (xb.CompareTo(yb) != -yb.CompareTo(xb))
-                    {
-                        fail("compareTo not anti-symmetric",
-                             xb, yb, x, y);
-                    }
-                    if ((xb.CompareTo(yb) == 0) != xb.equals(yb))
-                    {
-                        fail("compareTo inconsistent with equals",
-                             xb, yb, x, y);
-                    }
-                    // from Long.compare(x, y)
-                    if (xb.CompareTo(yb) != ((x < y) ? -1 : ((x == y) ? 0 : 1)))
-                    {
-
-                        fail("Incorrect results for LongBuffer.compareTo",
-                             xb, yb, x, y);
-                    }
-                    if (xb.equals(yb) != ((x == y) /*|| (x != x) && (y != y)*/))
-                    {
-                        fail("Incorrect results for LongBuffer.equals",
-                             xb, yb, x, y);
-                    }
-                }
-            }
-
-            // Sub, dup
-
-            relPut(b);
-            relGet(b.Duplicate());
-            b.Position = (13);
-            relGet(b.Duplicate(), 13);
-            relGet(b.Duplicate().Slice(), 13);
-            relGet(b.Slice(), 13);
-            relGet(b.Slice().Duplicate(), 13);
-
-            // Slice
-
-            b.Position = (5);
-            Int64Buffer sb = b.Slice();
-            checkSlice(b, sb);
-            b.Position = (0);
-            Int64Buffer sb2 = sb.Slice();
-            checkSlice(sb, sb2);
-
-            if (!sb.equals(sb2))
-                fail("Sliced slices do not match", sb, sb2);
-            if ((sb.HasArray) && (sb.ArrayOffset != sb2.ArrayOffset))
-                fail("Array offsets do not match: "
-                     + sb.ArrayOffset + " != " + sb2.ArrayOffset, sb, sb2);
-
-
-            // Read-only views
-
-            b.Rewind();
-
-            // LUCENENET: AsReadOnlyBuffer() not implemented
-            tryCatch(b, typeof(NotImplementedException), () =>
-            {
-                b.AsReadOnlyBuffer();
-            });
-
-            // LUCENENET: AsReadOnlyBuffer() not implemented
-            //LongBuffer rb = b.AsReadOnlyBuffer();
-            //if (!b.Equals(rb))
-            //    fail("Buffer not equal to read-only view", b, rb);
-            //Show(level + 1, rb);
-
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    relPut(rb);
-            //});
-
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    absPut(rb);
-            //});
-
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    bulkPutArray(rb);
-            //});
-
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    bulkPutBuffer(rb);
-            //});
-
-            //// put(LongBuffer) should not change source position
-            //LongBuffer src = LongBuffer.Allocate(1);
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    rb.Put(src);
-            //});
-            //ck(src, src.Position, 0);
-
-            //tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //{
-            //    rb.Compact();
-            //});
-
-
-            //if (rb.GetType().Name.StartsWith("Heap", StringComparison.Ordinal))
-            //{
-
-            //    tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //    {
-            //        var x = rb.Array;
-            //    });
-
-            //    tryCatch(b, typeof(ReadOnlyBufferException), () =>
-            //    {
-            //        var x = rb.ArrayOffset;
-            //    });
-
-            //    if (rb.HasArray)
-            //        fail("Read-only heap buffer's backing array is accessible",
-            //             rb);
-
-            //}
-
-            // Bulk puts from read-only buffers
-
-            b.Clear();
-            //rb.Rewind();
-            //b.Put(rb);
-
-            relPut(b);                       // Required by testViews
-
-        }
-
-
-        public static void test(long[] ba)
-        {
-            int offset = 47;
-            int length = 900;
-            Int64Buffer b = Int64Buffer.Wrap(ba, offset, length);
-            Show(0, b);
-            ck(b, b.Capacity, ba.Length);
-            ck(b, b.Position, offset);
-            ck(b, b.Limit, offset + length);
-
-            // The offset must be non-negative and no larger than <array.length>.
-            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
-            {
-                Int64Buffer.Wrap(ba, -1, ba.Length);
-            });
-            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
-            {
-                Int64Buffer.Wrap(ba, ba.Length + 1, ba.Length);
-            });
-            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
-            {
-                Int64Buffer.Wrap(ba, 0, -1);
-            });
-            tryCatch(ba, typeof(ArgumentOutOfRangeException), () =>
-            {
-                Int64Buffer.Wrap(ba, 0, ba.Length + 1);
-            });
-
-            // A NullPointerException will be thrown if the array is null.
-            tryCatch(ba, typeof(NullReferenceException), () =>
-            {
-                Int64Buffer.Wrap((long[])null, 0, 5);
-            });
-            tryCatch(ba, typeof(NullReferenceException), () =>
-            {
-                Int64Buffer.Wrap((long[])null);
-            });
-        }
-
-
-        public static void TestAllocate()
-        {
-            // An IllegalArgumentException will be thrown for negative capacities.
-            tryCatch((Buffer)null, typeof(ArgumentException), () =>
-            {
-                Int64Buffer.Allocate(-1);
-            });
-        }
-
-        [Test, LuceneNetSpecific]
-        public static void Test()
-        {
-            TestAllocate();
-            test(0, Int64Buffer.Allocate(7 * 1024), false);
-            test(0, Int64Buffer.Wrap(new long[7 * 1024], 0, 7 * 1024), false);
-            test(new long[1024]);
-
-            callReset(Int64Buffer.Allocate(10));
-            putBuffer();
-
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs
index 7ba8993..3ea32c9 100644
--- a/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs
+++ b/src/Lucene.Net.Tests/Util/Packed/TestPackedInts.cs
@@ -4,6 +4,7 @@ using System.Globalization;
 using System.IO;
 using Lucene.Net.Randomized.Generators;
 using Lucene.Net.Support;
+using Lucene.Net.Support.IO;
 using NUnit.Framework;
 
 namespace Lucene.Net.Util.Packed

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj
index a989115..ca7fffe 100644
--- a/src/Lucene.Net/Lucene.Net.csproj
+++ b/src/Lucene.Net/Lucene.Net.csproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <!--
 
  Licensed to the Apache Software Foundation (ASF) under one
@@ -19,7 +19,6 @@
  under the License.
 
 -->
-
 <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"
/>
   <PropertyGroup>
@@ -618,14 +617,10 @@
     <Compile Include="Support\AtomicLong.cs" />
     <Compile Include="Support\AtomicObject.cs" />
     <Compile Include="Support\AtomicReferenceArray.cs" />
-    <Compile Include="Support\Buffer.cs" />
     <Compile Include="Support\AttributeItem.cs" />
     <Compile Include="Support\BitArrayExtensions.cs" />
-    <Compile Include="Support\BufferExceptions.cs" />
     <Compile Include="Support\BundleResourceManagerFactory.cs" />
     <Compile Include="Support\ByteArrayOutputStream.cs" />
-    <Compile Include="Support\ByteBuffer.cs" />
-    <Compile Include="Support\ByteOrder.cs" />
     <Compile Include="Support\C5.Support.cs" />
     <Compile Include="Support\Character.cs" />
     <Compile Include="Support\Arrays.cs" />
@@ -654,7 +649,7 @@
     <Compile Include="Support\ExceptionExtensions.cs" />
     <Compile Include="Support\ExceptionToClassNameConventionAttribute.cs" />
     <Compile Include="Support\ExceptionToNullableEnumConvention.cs" />
-    <Compile Include="Support\FileStreamExtensions.cs" />
+    <Compile Include="Support\IO\FileStreamExtensions.cs" />
     <Compile Include="Support\ICallable.cs" />
     <Compile Include="Support\ICharSequence.cs" />
     <Compile Include="Support\ICompletionService.cs" />
@@ -664,17 +659,28 @@
     <Compile Include="Support\IdentityHashMap.cs" />
     <Compile Include="Support\IdentityHashSet.cs" />
     <Compile Include="Support\IdentityWeakReference.cs" />
+    <Compile Include="Support\IO\Buffer.cs" />
+    <Compile Include="Support\IO\BufferExceptions.cs" />
+    <Compile Include="Support\IO\ByteBuffer.cs" />
     <Compile Include="Support\DictionaryExtensions.cs" />
     <Compile Include="Support\ExceptionToNetNumericConventionAttribute.cs" />
     <Compile Include="Support\IndexWriterConfigExtensions.cs" />
+    <Compile Include="Support\IO\ByteOrder.cs" />
+    <Compile Include="Support\IO\Endianness.cs" />
+    <Compile Include="Support\IO\HeapByteBuffer.cs" />
+    <Compile Include="Support\IO\LongArrayBuffer.cs" />
+    <Compile Include="Support\IO\LongBuffer.cs" />
+    <Compile Include="Support\IO\LongToByteBufferAdapter.cs" />
+    <Compile Include="Support\IO\ReadOnlyHeapByteBuffer.cs" />
+    <Compile Include="Support\IO\ReadWriteHeapByteBuffer.cs" />
+    <Compile Include="Support\IO\ReadWriteLongArrayBuffer.cs" />
     <Compile Include="Support\IResourceManagerFactory.cs" />
     <Compile Include="Support\LimitedConcurrencyLevelTaskScheduler.cs" />
     <Compile Include="Support\LinkedHashMap.cs" />
     <Compile Include="Support\ListExtensions.cs" />
-    <Compile Include="Support\LongBuffer.cs" />
     <Compile Include="Support\LurchTable.cs" />
     <Compile Include="Support\MathExtension.cs" />
-    <Compile Include="Support\MemoryMappedFileByteBuffer.cs" />
+    <Compile Include="Support\IO\MemoryMappedFileByteBuffer.cs" />
     <Compile Include="Support\NumberFormat.cs" />
     <Compile Include="Support\PriorityQueue.cs" />
     <Compile Include="Support\ReaderWriterLockSlimExtensions.cs" />
@@ -907,4 +913,4 @@
     </Compile>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.Targets" />
-</Project>
+</Project>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Store/ByteBufferIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/ByteBufferIndexInput.cs b/src/Lucene.Net/Store/ByteBufferIndexInput.cs
index 7b898ba..bda469c 100644
--- a/src/Lucene.Net/Store/ByteBufferIndexInput.cs
+++ b/src/Lucene.Net/Store/ByteBufferIndexInput.cs
@@ -1,4 +1,4 @@
-using Lucene.Net.Support;
+using Lucene.Net.Support.IO;
 using Lucene.Net.Util;
 using System;
 using System.Diagnostics;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Store/MMapDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/MMapDirectory.cs b/src/Lucene.Net/Store/MMapDirectory.cs
index dcba346..ee1ac8c 100644
--- a/src/Lucene.Net/Store/MMapDirectory.cs
+++ b/src/Lucene.Net/Store/MMapDirectory.cs
@@ -1,4 +1,5 @@
 using Lucene.Net.Support;
+using Lucene.Net.Support.IO;
 using System;
 using System.Diagnostics;
 using System.IO;
@@ -355,7 +356,8 @@ namespace Lucene.Net.Store
                     adjust = 1;
                 }
 
-                buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset
+ bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
+                //buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset
+ bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
+                buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset
+ bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), bufSize);
                 bufferStart += bufSize;
             }
 

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Store/NIOFSDirectory.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Store/NIOFSDirectory.cs b/src/Lucene.Net/Store/NIOFSDirectory.cs
index d1f268b..1649401 100644
--- a/src/Lucene.Net/Store/NIOFSDirectory.cs
+++ b/src/Lucene.Net/Store/NIOFSDirectory.cs
@@ -1,4 +1,5 @@
 using Lucene.Net.Support;
+using Lucene.Net.Support.IO;
 using System;
 using System.Diagnostics;
 using System.IO;

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Support/Buffer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/Buffer.cs b/src/Lucene.Net/Support/Buffer.cs
deleted file mode 100644
index ba0bb4e..0000000
--- a/src/Lucene.Net/Support/Buffer.cs
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-using System;
-
-namespace Lucene.Net.Support
-{
-    /// <summary>
-    /// Base class for <see cref="ByteBuffer"/> and <see cref="Int64Buffer"/>
(ported from Java)
-    /// </summary>
-#if FEATURE_SERIALIZABLE
-    [Serializable]
-#endif
-    public abstract class Buffer
-    {
-        private int mark = -1;
-        private int position;
-        private int capacity;
-        private int limit;
-
-        // Used only by direct buffers
-        // NOTE: hoisted here for speed in JNI GetDirectBufferAddress
-        internal long address;
-
-        /// <summary>
-        /// Creates a new buffer with the given mark, position, limit, and capacity,
-        /// after checking invariants.
-        /// </summary>
-        internal Buffer(int mark, int pos, int lim, int cap)
-        {
-            if (cap < 0)
-                throw new ArgumentException("Negative capacity: " + cap);
-            this.capacity = cap;
-            SetLimit(lim);
-            SetPosition(pos);
-            if (mark >= 0)
-            {
-                if (mark > pos)
-                    throw new ArgumentException("mark > position: ("
-                                                       + mark + " > " + pos + ")");
-                this.mark = mark;
-            }
-        }
-
-        /// <summary>
-        /// Returns this buffer's capacity.
-        /// </summary>
-        public int Capacity
-        {
-            get { return capacity; }
-        }
-
-        /// <summary>
-        /// Returns this buffer's position.
-        /// </summary>
-        public int Position
-        {
-            get { return position; }
-            set { SetPosition(value); }
-        }
-
-        /// <summary>
-        /// Sets this buffer's position.  If the mark is defined and larger than the
-        /// new position then it is discarded.
-        /// </summary>
-        /// <param name="newPosition">The new position value; must be non-negative
and no larger than the current limit</param>
-        /// <returns>This buffer</returns>
-        /// <exception cref="ArgumentException">If the preconditions on <paramref
name="newPosition"/> do not hold</exception>
-        public Buffer SetPosition(int newPosition)
-        {
-            if ((newPosition > limit) || (newPosition < 0))
-                throw new ArgumentException();
-            position = newPosition;
-            if (mark > position) mark = -1;
-            return this;
-        }
-
-
-        /// <summary>
-        /// Returns this buffer's limit.
-        /// </summary>
-        public int Limit
-        {
-            get { return limit; }
-            set { SetLimit(value); }
-        }
-
-        /// <summary>
-        /// Sets this buffer's limit.  If the position is larger than the new limit
-        /// then it is set to the new limit.  If the mark is defined and larger than
-        /// the new limit then it is discarded.
-        /// </summary>
-        /// <param name="newLimit">The new limit value; must be non-negative and no
larger than this buffer's capacity</param>
-        /// <returns>This buffer</returns>
-        /// <exception cref="ArgumentException">If the preconditions on <paramref
name="newLimit"/> do not hold</exception>
-        public Buffer SetLimit(int newLimit)
-        {
-            if ((newLimit > capacity) || (newLimit < 0))
-                throw new ArgumentException();
-            limit = newLimit;
-            if (position > limit) position = limit;
-            if (mark > limit) mark = -1;
-            return this;
-        }
-
-        /// <summary>
-        /// Sets this buffer's mark at its position.
-        /// </summary>
-        /// <returns>This buffer</returns>
-        public Buffer Mark()
-        {
-            mark = position;
-            return this;
-        }
-
-        /// <summary>
-        /// Resets this buffer's position to the previously-marked position.
-        /// 
-        /// <para>
-        /// Invoking this method neither changes nor discards the mark's
-        /// value.
-        /// </para>
-        /// </summary>
-        /// <returns>This buffer</returns>
-        /// <exception cref="InvalidMarkException">If the mark has not been set</exception>
-        public Buffer Reset()
-        {
-            int m = mark;
-            if (m < 0)
-                throw new InvalidMarkException();
-            position = m;
-            return this;
-        }
-
-        /// <summary>
-        /// Clears this buffer.  The position is set to zero, the limit is set to
-        /// the capacity, and the mark is discarded.
-        /// 
-        /// <para>
-        /// Invoke this method before using a sequence of channel-read or
-        /// <c>Put</c> operations to fill this buffer.  For example:
-        /// 
-        /// <code>
-        /// buf.Clear();     // Prepare buffer for reading
-        /// in.Read(buf);    // Read data
-        /// </code>
-        /// </para>
-        /// <para>
-        /// This method does not actually erase the data in the buffer, but it
-        /// is named as if it did because it will most often be used in situations
-        /// in which that might as well be the case.
-        /// </para>
-        /// </summary>
-        /// <returns>This buffer</returns>
-        public Buffer Clear()
-        {
-            position = 0;
-            limit = capacity;
-            mark = -1;
-            return this;
-        }
-
-        /// <summary>
-        /// Flips this buffer.  The limit is set to the current position and then
-        /// the position is set to zero.  If the mark is defined then it is
-        /// discarded.
-        /// 
-        /// <para>
-        /// After a sequence of channel-read or <c>Put</c> operations, invoke
-        /// this method to prepare for a sequence of channel-write or relative
-        /// <c>Get</c> operations.  For example:
-        /// 
-        /// <code>
-        /// buf.Put(magic);    // Prepend header
-        /// in.Read(buf);      // Read data into rest of buffer
-        /// buf.Flip();        // Flip buffer
-        /// out.Write(buf);    // Write header + data to channel
-        /// </code>
-        /// </para>
-        /// <para>
-        /// This method is often used in conjunction with the <see cref="ByteBuffer.Compact()"/>
-        /// method when transferring data from one place to another.
-        /// </para>
-        /// </summary>
-        /// <returns>This buffer</returns>
-        public Buffer Flip()
-        {
-            limit = position;
-            position = 0;
-            mark = -1;
-            return this;
-        }
-
-        /// <summary>
-        /// Rewinds this buffer.  The position is set to zero and the mark is
-        /// discarded.
-        /// 
-        /// <para>
-        /// Invoke this method before a sequence of channel-write or <c>Get</c>
-        /// operations, assuming that the limit has already been set
-        /// appropriately.  For example:
-        /// 
-        /// <code>
-        /// out.Write(buf);    // Write remaining data
-        /// buf.Rewind();      // Rewind buffer
-        /// buf.Get(array);    // Copy data into array
-        /// </code>
-        /// </para>
-        /// </summary>
-        /// <returns>This buffer</returns>
-        public Buffer Rewind()
-        {
-            position = 0;
-            mark = -1;
-            return this;
-        }
-
-        /// <summary>
-        /// Returns the number of elements between the current position and the
-        /// limit.
-        /// </summary>
-        public int Remaining
-        {
-            get { return limit - position; }
-        }
-
-        /// <summary>
-        /// Tells whether there are any elements between the current position and
-        /// the limit.
-        /// </summary>
-        public bool HasRemaining
-        {
-            get { return position < limit; }
-        }
-
-        /// <summary>
-        /// Tells whether or not this buffer is read-only.
-        /// </summary>
-        /// <returns>
-        /// <c>true</c> if, and only if, this buffer is read-only
-        /// </returns>
-        public abstract bool IsReadOnly { get; }
-
-        /// <summary>
-        /// Tells whether or not this buffer is backed by an accessible
-        /// array.
-        /// 
-        /// <para>
-        /// If this method returns <c>true</c> then the <see cref="Array"/>

-        /// and <see cref="ArrayOffset"/> properties may be safely invoked.
-        /// </para>
-        /// </summary>
-        /// <returns>
-        /// <c>true</c> if, and only if, this buffer is backed by an array and
is not read-only
-        /// </returns>
-        public abstract bool HasArray { get; }
-
-        /// <summary>
-        /// Returns the array that backs this
-        /// buffer&nbsp;&nbsp;<i>(optional operation)</i>.
-        /// 
-        /// <para>
-        /// This property is intended to allow array-backed buffers to be
-        /// passed to native code more efficiently. Concrete subclasses
-        /// provide more strongly-typed return values for this property.
-        /// </para>
-        /// <para>
-        /// Modifications to this buffer's content will cause the returned
-        /// array's content to be modified, and vice versa.
-        /// </para>
-        /// <para>
-        /// Check the <see cref="HasArray"/> property before using this
-        /// property in order to ensure that this buffer has an accessible backing
-        /// array.
-        /// </para>
-        /// </summary>
-        /// <returns>
-        /// The array that backs this buffer
-        /// </returns>
-        /// <exception cref="ReadOnlyBufferException">If this buffer is backed by an
array but is read-only</exception>
-        /// <exception cref="InvalidOperationException">If this buffer is not backed
by an accessible array</exception>
-        public abstract object Array { get; }
-
-
-        /// <summary>
-        /// Returns the offset within this buffer's backing array of the first
-        /// element of the buffer&nbsp;&nbsp;<i>(optional operation)</i>.
-        /// 
-        /// <para>
-        /// If this buffer is backed by an array then buffer position <c>p</c>
-        /// corresponds to array index <c>p</c>&nbsp;+&nbsp;<see cref="ArrayOffset"/><c>.
-        /// </para>
-        /// <para>
-        /// Check the <see cref="HasArray"/> property before using this
-        /// property in order to ensure that this buffer has an accessible backing
-        /// array.
-        /// </para>
-        /// </summary>
-        /// <returns>
-        /// The offset within this buffer's array
-        /// of the first element of the buffer
-        /// </returns>
-        /// <exception cref="ReadOnlyBufferException">If this buffer is backed by an
array but is read-only</exception>
-        /// <exception cref="InvalidOperationException">If this buffer is not backed
by an accessible array</exception>
-        public abstract int ArrayOffset { get; }
-
-        /// <summary>
-        /// Tells whether or not this buffer is <c>direct</c>
-        /// </summary>
-        /// <returns><c>true</c> if, and only if, this buffer is direct</returns>
-        public abstract bool IsDirect { get; }
-
-        // -- internal members for bounds checking, etc. --
-
-        /// <summary>
-        /// Checks the current position against the limit, throwing a
-        /// <see cref="BufferUnderflowException"/> if it is not smaller than the limit,
and then
-        /// increments the position.
-        /// </summary>
-        /// <returns>The current position value, before it is incremented</returns>
-        internal int NextGetIndex()
-        {
-            if (position >= limit)
-                throw new BufferUnderflowException();
-            return position++;
-        }
-
-        internal int NextGetIndex(int nb)
-        {
-            if (limit - position < nb)
-                throw new BufferUnderflowException();
-            int p = position;
-            position += nb;
-            return p;
-        }
-
-        /// <summary>
-        /// Checks the current position against the limit, throwing a <see cref="BufferOverflowException"/>
-        /// if it is not smaller than the limit, and then
-        /// increments the position.
-        /// </summary>
-        /// <returns>The current position value, before it is incremented</returns>
-        internal int NextPutIndex()
-        {
-            if (position >= limit)
-                throw new BufferOverflowException();
-            return position++;
-        }
-
-        internal int NextPutIndex(int nb)
-        {
-            if (limit - position < nb)
-                throw new BufferOverflowException();
-            int p = position;
-            position += nb;
-            return p;
-        }
-
-        /// <summary>
-        /// Checks the given index against the limit, throwing an <see cref="IndexOutOfRangeException"/>

-        /// if it is not smaller than the limit or is smaller than zero.
-        /// </summary>
-        /// <param name="i"></param>
-        /// <returns></returns>
-        internal int CheckIndex(int i)
-        {
-            if ((i < 0) || (i >= limit))
-                throw new IndexOutOfRangeException();
-            return i;
-        }
-
-        internal int CheckIndex(int i, int nb)
-        {
-            if ((i < 0) || (nb > limit - i))
-                throw new IndexOutOfRangeException();
-            return i;
-        }
-
-        internal int MarkValue
-        {
-            get { return mark; }
-        }
-
-        internal void Truncate()
-        {
-            mark = -1;
-            position = 0;
-            limit = 0;
-            capacity = 0;
-        }
-
-        internal void DiscardMark()
-        {
-            mark = -1;
-        }
-
-        internal static void CheckBounds(int off, int len, int size)
-        {
-            if ((off | len | (off + len) | (size - (off + len))) < 0)
-                throw new IndexOutOfRangeException();
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/38d3a3d5/src/Lucene.Net/Support/BufferExceptions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/BufferExceptions.cs b/src/Lucene.Net/Support/BufferExceptions.cs
deleted file mode 100644
index 4ffc38c..0000000
--- a/src/Lucene.Net/Support/BufferExceptions.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-using System;
-#if FEATURE_SERIALIZABLE
-using System.Runtime.Serialization;
-#endif
-
-namespace Lucene.Net.Support
-{
-#if FEATURE_SERIALIZABLE
-    [Serializable]
-#endif
-    internal sealed class BufferUnderflowException : Exception
-    {
-        public BufferUnderflowException()
-        {
-        }
-
-#if FEATURE_SERIALIZABLE
-        /// <summary>
-        /// Initializes a new instance of this class with serialized data.
-        /// </summary>
-        /// <param name="info">The <see cref="SerializationInfo"/> that holds
the serialized object data about the exception being thrown.</param>
-        /// <param name="context">The <see cref="StreamingContext"/> that contains
contextual information about the source or destination.</param>
-        public BufferUnderflowException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-
-#if FEATURE_SERIALIZABLE
-    [Serializable]
-#endif
-    internal sealed class BufferOverflowException : Exception
-    {
-        public BufferOverflowException()
-        {
-        }
-
-#if FEATURE_SERIALIZABLE
-        /// <summary>
-        /// Initializes a new instance of this class with serialized data.
-        /// </summary>
-        /// <param name="info">The <see cref="SerializationInfo"/> that holds
the serialized object data about the exception being thrown.</param>
-        /// <param name="context">The <see cref="StreamingContext"/> that contains
contextual information about the source or destination.</param>
-        public BufferOverflowException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-
-#if FEATURE_SERIALIZABLE
-    [Serializable]
-#endif
-    internal sealed class ReadOnlyBufferException : Exception
-    {
-        public ReadOnlyBufferException()
-        {
-        }
-
-#if FEATURE_SERIALIZABLE
-        /// <summary>
-        /// Initializes a new instance of this class with serialized data.
-        /// </summary>
-        /// <param name="info">The <see cref="SerializationInfo"/> that holds
the serialized object data about the exception being thrown.</param>
-        /// <param name="context">The <see cref="StreamingContext"/> that contains
contextual information about the source or destination.</param>
-        public ReadOnlyBufferException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-
-#if FEATURE_SERIALIZABLE
-    [Serializable]
-#endif
-    internal sealed class InvalidMarkException : Exception
-    {
-        public InvalidMarkException()
-        {
-        }
-
-#if FEATURE_SERIALIZABLE
-        /// <summary>
-        /// Initializes a new instance of this class with serialized data.
-        /// </summary>
-        /// <param name="info">The <see cref="SerializationInfo"/> that holds
the serialized object data about the exception being thrown.</param>
-        /// <param name="context">The <see cref="StreamingContext"/> that contains
contextual information about the source or destination.</param>
-        public InvalidMarkException(SerializationInfo info, StreamingContext context)
-            : base(info, context)
-        {
-        }
-#endif
-    }
-}
\ No newline at end of file


Mime
View raw message