Exemplo n.º 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @EnumSource(BufferFactories.class) void shouldThrowExceptionForReadAfterEOFIfNotEnoughBytesExist(System.Func<int, ByteBuffer> bufferFactory) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldThrowExceptionForReadAfterEOFIfNotEnoughBytesExist(System.Func <int, ByteBuffer> bufferFactory)
        {
            // Given
            StoreChannel storeChannel = FileSystem.open(new File("foo.txt"), OpenMode.READ_WRITE);
            ByteBuffer   buffer       = ByteBuffer.allocate(1);

            buffer.put(( sbyte )1);
            buffer.flip();
            storeChannel.WriteAll(buffer);
            storeChannel.Force(false);
            storeChannel.close();

            storeChannel = FileSystem.open(new File("foo.txt"), OpenMode.READ);

            ReadAheadChannel <StoreChannel> channel = new ReadAheadChannel <StoreChannel>(storeChannel, bufferFactory(DEFAULT_READ_AHEAD_SIZE));

            assertEquals(( sbyte )1, channel.Get());

            try
            {
                channel.Get();
                fail("Should have thrown exception signalling end of file reached");
            }
            catch (ReadPastEndException)
            {
                // outstanding
            }

            try
            {
                channel.Get();
                fail("Should have thrown exception signalling end of file reached");
            }
            catch (ReadPastEndException)
            {
                // outstanding
            }
        }
Exemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @ParameterizedTest @EnumSource(BufferFactories.class) void shouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered(System.Func<int, ByteBuffer> bufferFactory) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReturnValueIfSufficientBytesAreBufferedEvenIfEOFHasBeenEncountered(System.Func <int, ByteBuffer> bufferFactory)
        {
            // Given
            StoreChannel storeChannel = FileSystem.open(new File("foo.txt"), OpenMode.READ_WRITE);
            ByteBuffer   buffer       = ByteBuffer.allocate(1);

            buffer.put(( sbyte )1);
            buffer.flip();
            storeChannel.WriteAll(buffer);
            storeChannel.Force(false);
            storeChannel.close();

            storeChannel = FileSystem.open(new File("foo.txt"), OpenMode.READ);
            ReadAheadChannel <StoreChannel> channel = new ReadAheadChannel <StoreChannel>(storeChannel, bufferFactory(DEFAULT_READ_AHEAD_SIZE));

            try
            {
                channel.Short;
                fail("Should have thrown exception signalling end of file reached");
            }
            catch (ReadPastEndException)
            {
                // outstanding
            }

            assertEquals(( sbyte )1, channel.Get());

            try
            {
                channel.Get();
                fail("Should have thrown exception signalling end of file reached");
            }
            catch (ReadPastEndException)
            {
                // outstanding
            }
        }