示例#1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldTrackAbsolutePosition() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldTrackAbsolutePosition()
        {
            // GIVEN
            string[][] data = new string[][]
            {
                new string[] { "this is", "the first line" },
                new string[] { "where this", "is the second line" }
            };
            RawIterator <CharReadable, IOException> readers = ReaderIteratorFromStrings(data, '\n');
            CharReadable reader = new MultiReadable(readers);

            assertEquals(0L, reader.Position());
            SectionedCharBuffer buffer = new SectionedCharBuffer(15);

            // WHEN
            reader.Read(buffer, buffer.Front());
            assertEquals(15, reader.Position());
            reader.Read(buffer, buffer.Front());
            assertEquals(23, reader.Position(), "Should not transition to a new reader in the middle of a read");
            assertEquals("Reader1", reader.SourceDescription());

            // we will transition to the new reader in the call below
            reader.Read(buffer, buffer.Front());
            assertEquals(23 + 15, reader.Position());
            reader.Read(buffer, buffer.Front());
            assertEquals(23 + 30, reader.Position());
            reader.Read(buffer, buffer.Front());
            assertFalse(buffer.HasAvailable());
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Parameters public static java.util.Collection<ReadMethod> readMethods()
        public static ICollection <ReadMethod> ReadMethods()
        {
            return(Arrays.asList((readable, length) =>
            {
                SectionedCharBuffer readText = new SectionedCharBuffer(length);
                readable.read(readText, readText.Front());
                return copyOfRange(readText.Array(), readText.Pivot(), readText.Front());
            }, (readable, length) =>
            {
                char[] result = new char[length];
                readable.read(result, 0, length);
                return result;
            }));
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public SectionedCharBuffer read(SectionedCharBuffer buffer, int from) throws java.io.IOException
        public override SectionedCharBuffer Read(SectionedCharBuffer buffer, int from)
        {
            while (true)
            {
                _current.read(buffer, from);
                if (buffer.HasAvailable())
                {
                    // OK we read something from the current reader
                    CheckNewLineRequirement(buffer.Array(), buffer.Front() - 1);
                    return(buffer);
                }

                // Even if there's no line-ending at the end of this source we should introduce one
                // otherwise the last line of this source and the first line of the next source will
                // look like one long line.
                if (_requiresNewLine)
                {
                    buffer.Append('\n');
                    _requiresNewLine = false;
                    return(buffer);
                }

                if (!GoToNextSource())
                {
                    break;
                }
                from = buffer.Pivot();
            }
            return(buffer);
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleReadAheadEmptyData() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldHandleReadAheadEmptyData()
        {
            // GIVEN
            TrackingReader actual        = new TrackingReader(0);
            int            bufferSize    = 10;
            CharReadable   aheadReadable = ThreadAheadReadable.ThreadAhead(actual, bufferSize);

            // WHEN
            actual.AwaitCompletedReadAttempts(1);

            // THEN
            SectionedCharBuffer buffer = new SectionedCharBuffer(bufferSize);

            buffer = aheadReadable.Read(buffer, buffer.Front());
            assertEquals(buffer.Pivot(), buffer.Back());
            assertEquals(buffer.Pivot(), buffer.Front());
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldReadAhead() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        internal virtual void ShouldReadAhead()
        {
            // GIVEN
            TrackingReader      actual      = new TrackingReader(23);
            int                 bufferSize  = 5;
            CharReadable        aheadReader = ThreadAheadReadable.ThreadAhead(actual, bufferSize);
            SectionedCharBuffer buffer      = new SectionedCharBuffer(bufferSize);

            // WHEN starting it up it should read and fill the buffer to the brim
            assertEquals(bufferSize, actual.AwaitCompletedReadAttempts(1));

            // WHEN we read one buffer
            int read = 0;

            buffer = aheadReader.Read(buffer, buffer.Front());
            AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize);
            read += buffer.Available();

            // and simulate reading all characters, i.e. back section will be empty in the new buffer
            buffer = aheadReader.Read(buffer, buffer.Front());
            AssertBuffer(Chars(read, bufferSize), buffer, 0, bufferSize);
            read += buffer.Available();

            // then simulate reading some characters, i.e. back section will contain some characters
            int keep = 2;

            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize);
            read += buffer.Available();

            keep   = 3;
            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            AssertBuffer(Chars(read - keep, bufferSize + keep), buffer, keep, bufferSize);
            read += buffer.Available();

            keep   = 1;
            buffer = aheadReader.Read(buffer, buffer.Front() - keep);
            assertEquals(3, buffer.Available());
            AssertBuffer(Chars(read - keep, buffer.Available() + keep), buffer, keep, 3);
            read += buffer.Available();
            assertEquals(23, read);
        }
示例#6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldComplyWithSpecifiedCharset(java.nio.charset.Charset charset) throws Exception
        private void ShouldComplyWithSpecifiedCharset(Charset charset)
        {
            // GIVEN
            string data = "abcåäö[]{}";
            File   file = WriteToFile(data, charset);

            // WHEN
            CharReadable        reader = Readables.Files(charset, file);
            SectionedCharBuffer buffer = new SectionedCharBuffer(100);

            buffer = reader.Read(buffer, buffer.Front());

            // THEN
            char[] expected = data.ToCharArray();
            char[] array    = buffer.Array();
            assertEquals(expected.Length, buffer.Available());
            for (int i = 0; i < expected.Length; i++)
            {
                assertEquals(expected[i], array[buffer.Pivot() + i]);
            }
        }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldTrackPosition() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldTrackPosition()
        {
            // GIVEN
            string data = "1234567890";
            //                 ^   ^
            CharReadable        reader = Readables.Wrap(data);
            SectionedCharBuffer buffer = new SectionedCharBuffer(4);

            // WHEN
            int expected = 0;

            do
            {
                buffer    = reader.Read(buffer, buffer.Front());
                expected += buffer.Available();

                // THEN
                assertEquals(expected, reader.Position());
            } while (buffer.HasAvailable());

            // and THEN
            assertEquals(data.ToCharArray().length, expected);
        }
示例#8
0
 private static void AssertBuffer(char[] expectedChars, SectionedCharBuffer buffer, int charsInBack, int charsInFront)
 {
     assertEquals(buffer.Pivot() - charsInBack, buffer.Back());
     assertEquals(buffer.Pivot() + charsInFront, buffer.Front());
     assertArrayEquals(expectedChars, copyOfRange(buffer.Array(), buffer.Back(), buffer.Front()));
 }