Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZOOKEEPER-3039 TxnLogToolkit uses Scanner badly #517

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.DateFormat;
import java.util.Date;
import java.util.Scanner;
Expand Down Expand Up @@ -98,7 +96,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 +129,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 +170,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 +199,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 @@ -29,7 +29,7 @@
import java.io.FileNotFoundException;
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 +138,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