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 shouldReturnPositionWithinBufferedStream(System.Func<int, ByteBuffer> bufferFactory) throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReturnPositionWithinBufferedStream(System.Func <int, ByteBuffer> bufferFactory)
        {
            // given
            File file = new File("foo.txt");

            int readAheadSize = 512;
            int fileSize      = readAheadSize * 8;

            CreateFile(FileSystem, file, fileSize);
            ReadAheadChannel <StoreChannel> bufferedReader = new ReadAheadChannel <StoreChannel>(FileSystem.open(file, OpenMode.READ), bufferFactory(readAheadSize));

            // when
            for (int i = 0; i < fileSize / Long.BYTES; i++)
            {
                assertEquals(Long.BYTES * i, bufferedReader.Position());
                bufferedReader.Long;
            }

            assertEquals(fileSize, bufferedReader.Position());

            try
            {
                bufferedReader.Long;
                fail();
            }
            catch (ReadPastEndException)
            {
                // expected
            }

            assertEquals(fileSize, bufferedReader.Position());
        }
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 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.º 3
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
            }
        }