/// <exception cref="System.IO.IOException"/> /// <exception cref="System.NotSupportedException"/> public virtual ByteBuffer Read(ByteBufferPool bufferPool, int maxLength, EnumSet< ReadOption> opts) { try { return ((HasEnhancedByteBufferAccess)@in).Read(bufferPool, maxLength, opts); } catch (InvalidCastException) { ByteBuffer buffer = ByteBufferUtil.FallbackRead(this, bufferPool, maxLength); if (buffer != null) { extendedReadBuffers.Put(buffer, bufferPool); } return buffer; } }
/// <exception cref="System.Exception"/> private static void TestFallbackImpl(InputStream stream, byte[] original) { TestEnhancedByteBufferAccess.RestrictedAllocatingByteBufferPool bufferPool = new TestEnhancedByteBufferAccess.RestrictedAllocatingByteBufferPool(stream is ByteBufferReadable ); ByteBuffer result = ByteBufferUtil.FallbackRead(stream, bufferPool, 10); NUnit.Framework.Assert.AreEqual(10, result.Remaining()); Assert.AssertArrayEquals(Arrays.CopyOfRange(original, 0, 10), ByteBufferToArray(result )); result = ByteBufferUtil.FallbackRead(stream, bufferPool, 5000); NUnit.Framework.Assert.AreEqual(5000, result.Remaining()); Assert.AssertArrayEquals(Arrays.CopyOfRange(original, 10, 5010), ByteBufferToArray (result)); result = ByteBufferUtil.FallbackRead(stream, bufferPool, 9999999); NUnit.Framework.Assert.AreEqual(11375, result.Remaining()); Assert.AssertArrayEquals(Arrays.CopyOfRange(original, 5010, 16385), ByteBufferToArray (result)); result = ByteBufferUtil.FallbackRead(stream, bufferPool, 10); NUnit.Framework.Assert.IsNull(result); }