Esempio n. 1
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);
        }
Esempio n. 2
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());
        }
Esempio n. 3
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);
        }