Skip to content

Commit

Permalink
ZOOKEEPER-3039. Use the same Scanner for all queries
Browse files Browse the repository at this point in the history
  • Loading branch information
anmolnar committed May 10, 2018
1 parent 6e64125 commit a196443
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Options getOptions() {
*/
public static void main(String[] args) throws Exception {
try (final TxnLogToolkit lt = parseCommandLine(args)) {
lt.dump(new InputStreamReader(System.in));
lt.dump(new Scanner(System.in));
lt.printStat();
} catch (TxnLogToolkitParseException e) {
System.err.println(e.getMessage() + "\n");
Expand Down Expand Up @@ -131,7 +131,7 @@ public TxnLogToolkit(boolean recoveryMode, boolean verbose, String txnLogFileNam
}
}

public void dump(Reader input) throws Exception {
public void dump(Scanner scanner) throws Exception {
crcFixed = 0;

FileHeader fhdr = new FileHeader();
Expand Down Expand Up @@ -172,7 +172,7 @@ public void dump(Reader input) throws Exception {
if (recoveryMode) {
if (!force) {
printTxn(bytes, "CRC ERROR");
if (askForFix(input)) {
if (askForFix(scanner)) {
crcValue = crc.getValue();
++crcFixed;
}
Expand Down Expand Up @@ -201,19 +201,17 @@ public void dump(Reader input) throws Exception {
}
}

private boolean askForFix(Reader input) throws TxnLogToolkitException {
try (Scanner scanner = new Scanner(input)) {
while (true) {
System.out.print("Would you like to fix it (Yes/No/Abort) ? ");
char answer = Character.toUpperCase(scanner.next().charAt(0));
switch (answer) {
case 'Y':
return true;
case 'N':
return false;
case 'A':
throw new TxnLogToolkitException(0, "Recovery aborted.");
}
private boolean askForFix(Scanner scanner) throws TxnLogToolkitException {
while (true) {
System.out.print("Would you like to fix it (Yes/No/Abort) ? ");
char answer = Character.toUpperCase(scanner.next().charAt(0));
switch (answer) {
case 'Y':
return true;
case 'N':
return false;
case 'A':
throw new TxnLogToolkitException(0, "Recovery aborted.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -138,7 +139,7 @@ public void testRecoveryInteractiveMode() throws Exception {
TxnLogToolkit lt = new TxnLogToolkit(true, false, logfile.toString(), false);

// Act
lt.dump(new StringReader("y\n"));
lt.dump(new Scanner("y\n"));

// Assert
String output = outContent.toString();
Expand Down

0 comments on commit a196443

Please sign in to comment.