summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Harry Cutts <hcutts@google.com> 2025-03-18 05:07:10 -0700
committer Android (Google) Code Review <android-gerrit@google.com> 2025-03-18 05:07:10 -0700
commitfcfe12631f7f865c5dfc1265d757b23487efd0a2 (patch)
tree2fe1772dc7f500ac437d9eacd7fb7c6f0a6a8f65
parent6f7b34b0261d7da95d19a7f218edb660cab8e5df (diff)
parent54cbe9b562fd5e2381144578011201839f562745 (diff)
Merge "uinput: don't read next line of evemu recording until peek" into main
-rw-r--r--cmds/uinput/src/com/android/commands/uinput/EvemuParser.java33
1 files changed, 22 insertions, 11 deletions
diff --git a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
index da991624e685..d3e62d5351f0 100644
--- a/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
+++ b/cmds/uinput/src/com/android/commands/uinput/EvemuParser.java
@@ -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;
}