Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 959cc55b authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Consume consecutive delimiters at beginning of refilled buffer" into main am: f4d84e1a

parents 5fd5eb2e f4d84e1a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -89,6 +89,12 @@ public class ProcFileReader implements Closeable {
        mTail -= count;
        if (mTail == 0) {
            fillBuf();

            if (mTail > 0 && mBuffer[0] == ' ') {
                // After filling the buffer, it contains more consecutive
                // delimiters that need to be skipped.
                consumeBuf(0);
            }
        }
    }

+40 −0
Original line number Diff line number Diff line
@@ -215,6 +215,46 @@ public class ProcFileReaderTest {
        assertFalse(reader.hasMoreData());
    }

    @Test
    public void testBufferSizeWithConsecutiveDelimiters() throws Exception {
        // Read numbers using very small buffer size, exercising fillBuf()
        // Include more consecutive delimiters than the buffer size.
        final ProcFileReader reader =
                buildReader("1   21  3  41           5  61  7  81 9   10\n", 3);

        assertEquals(1, reader.nextInt());
        assertEquals(21, reader.nextInt());
        assertEquals(3, reader.nextInt());
        assertEquals(41, reader.nextInt());
        assertEquals(5, reader.nextInt());
        assertEquals(61, reader.nextInt());
        assertEquals(7, reader.nextInt());
        assertEquals(81, reader.nextInt());
        assertEquals(9, reader.nextInt());
        assertEquals(10, reader.nextInt());
        reader.finishLine();
        assertFalse(reader.hasMoreData());
    }

    @Test
    public void testBufferSizeWithConsecutiveDelimitersAndMultipleLines() throws Exception {
        final ProcFileReader reader =
                buildReader("1 21  41    \n    5  7     81   \n    9 10     \n", 3);

        assertEquals(1, reader.nextInt());
        assertEquals(21, reader.nextInt());
        assertEquals(41, reader.nextInt());
        reader.finishLine();
        assertEquals(5, reader.nextInt());
        assertEquals(7, reader.nextInt());
        assertEquals(81, reader.nextInt());
        reader.finishLine();
        assertEquals(9, reader.nextInt());
        assertEquals(10, reader.nextInt());
        reader.finishLine();
        assertFalse(reader.hasMoreData());
    }

    @Test
    public void testIgnore() throws Exception {
        final ProcFileReader reader = buildReader("a b c\n");