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

Commit fcfe1263 authored by Harry Cutts's avatar Harry Cutts Committed by Android (Google) Code Review
Browse files

Merge "uinput: don't read next line of evemu recording until peek" into main

parents 6f7b34b0 54cbe9b5
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -48,12 +48,17 @@ public class EvemuParser implements EventParser {

    private static class CommentAwareReader {
        private final LineNumberReader mReader;
        private String mPreviousLine;
        private String mNextLine;
        /** The previous line of the file, or {@code null} if we're at the start of the file. */
        private @Nullable String mPreviousLine;
        /**
         * The next line of the file to be returned from {@link #peekLine()}, or {@code null} if we
         * haven't peeked since the last {@link #advance()} or are at the end of the file.
         */
        private @Nullable String mNextLine;
        private boolean mAtEndOfFile = false;

        CommentAwareReader(LineNumberReader in) throws IOException {
        CommentAwareReader(LineNumberReader in) {
            mReader = in;
            mNextLine = findNextLine();
        }

        private @Nullable String findNextLine() throws IOException {
@@ -61,7 +66,7 @@ public class EvemuParser implements EventParser {
            while (line != null && line.length() == 0) {
                String unstrippedLine = mReader.readLine();
                if (unstrippedLine == null) {
                    // End of file.
                    mAtEndOfFile = true;
                    return null;
                }
                line = stripComments(unstrippedLine);
@@ -85,22 +90,28 @@ public class EvemuParser implements EventParser {
         * {@code null} if the end of the file is reached. However, it does not advance to the
         * next line of the file.
         */
        public @Nullable String peekLine() {
        public @Nullable String peekLine() throws IOException {
            if (mNextLine == null && !mAtEndOfFile) {
                mNextLine = findNextLine();
            }
            return mNextLine;
        }

        /** Moves to the next line of the file. */
        public void advance() throws IOException {
        public void advance() {
            mPreviousLine = mNextLine;
            mNextLine = findNextLine();
            mNextLine = null;
        }

        public boolean isAtEndOfFile() {
            return mNextLine == null;
            return mAtEndOfFile;
        }

        /** Returns the previous line, for error messages. */
        public String getPreviousLine() {
        /**
         * Returns the previous line, for error messages. Will be {@code null} if we're at the start
         * of the file.
         */
        public @Nullable String getPreviousLine() {
            return mPreviousLine;
        }